开发者

Stretching out an multidimensional array

Is there any built in MATLAB command that "stretches" out a multidimensional array into a linear array?

开发者_如何学运维

e.g [1,2;3,4] should be come [1,2,3,4]


You can also use the colon operator:

x = [1 2; 3 4];
y = x(:);


The reshape command can do this:

x = [1 2; 3 4];
y = reshape(x, 1, []);

The empty array [] indicates that MATLAB should calculate automatically how many elements should go in that direction (i.e., that you won't have to specify the number of elements in your array).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜