在MATLAB中将column_vector更改为矩阵

时间:2011-06-14 20:50:37

标签: matrix

我有一个需要更改为矩阵的列向量。矩阵的大小已指定并可以更改。请建议一个矢量化解决方案。

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 ] ;

谢谢!

1 个答案:

答案 0 :(得分:1)

reshape函数执行此操作:

>> 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
相关问题