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).
精彩评论