Reshape MATLAB vector in Row-wise manner

后端 未结 3 382
遇见更好的自我
遇见更好的自我 2021-02-05 11:17

Say I have a matrix a = [1 2 3 4 5 6];, how do I reshape it in a row-wise manner for example reshape(a, 2, 3) to yield

1 2 3 
4 5 6
         


        
3条回答
  •  遇见更好的自我
    2021-02-05 12:08

    The general way to reshape an m*n matrix A to a p*k matrix B in a row-wise manner is:

    c=reshape(A',1,m*n) 
    B=reshape(c,k,p)' 
    example: m=3 n=4 , p=6, q=2
    A=[1 2 3 4; 5 6 7 8; 9 10 11 12] 
    c=[1 2 3 4 5 6 7 8 9 10 11 12] 
    B=[1 2 ; 3 4; 5 6; 7 8; 9 10; 11 12] 
    

提交回复
热议问题