开发者

Stretching out an multidimensional array

开发者 https://www.devze.com 2023-04-11 17:25 出处:网络
Is there any built in MATLAB command that \"stretches\" out a multidimensional array into a linear 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

精彩评论

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