当前位置: 动力学知识库 > 问答 > 编程问答 >

matrix - Mathematical Operations on 3D Array - MATLAB

问题描述:

I have a mx1xn array (currently m=n=3), and I need to subtract from each column one value stored in a 1x1xn column.

i.e. n represents time, and from each instance of time, I need to subtract a different time-dependent constant from the data (1xm or whatever the dimensions are).

What is the best way to go at it? My attempt wont work:

data(:,2,:) - constants(:,2,:) %constants in this case is 1x1x3, data is 3x1x3

One attempt would be to loop it, but I'm wondering what is a more efficient way.

网友答案:

Use bsxfun:

bsxfun(@minus, data, constants)
分享给朋友:
您可能感兴趣的文章:
随机阅读: