matlab - How do you concatenate the rows of a matrix into a vector? -
for m-by-m (square) array, how concatenate rows column vector size m^2 ?
there couple of different ways can collapse matrix vector, depending upon how want contents of matrix fill vector. here 2 examples, 1 using function reshape , 1 using colon syntax (:)
:
>> m = [1 2 3; 4 5 6; 7 8 9]; %# sample matrix >> vector = reshape(m.',[],1) %# collect row contents column vector vector = 1 2 3 4 5 6 7 8 9 >> vector = m(:) %# collect column contents column vector vector = 1 4 7 2 5 8 3 6 9
Comments
Post a Comment