开发者

Change a column_vector to a matrix in MATLAB

I have a column vec开发者_运维技巧tor that needs to be changed into a matrix. The size of matrix is specified and can change. Please suggest a vectorized solution.

rows = 3 ; cols = 4 ; %matrix elements for this case = 12

colvector = [ 2;4;5;8;10;14;16;18;20;21;28;30] ;

desired_mat = [ ...
               2     4     5     8
              10    14    16    18
              20    21    28    30 ] ;

Thanks!


The reshape function does that:

>> colvector = [ 2;4;5;8;10;14;16;18;20;21;28;30] ;
>> A = reshape(colvector, 3, 4)

A =

     2     8    16    21
     4    10    18    28
     5    14    20    30
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜