Reshape MATLAB vector in Row-wise manner

后端 未结 3 380
遇见更好的自我
遇见更好的自我 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 11:53

    It is indeed reshape(A',cols,rows)'

    ( reshape(a', 3, 2)' in your example)

    0 讨论(0)
  • 2021-02-05 11:54

    How about this?

    reshape(a, 3, 2)'

    0 讨论(0)
  • 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] 
    
    0 讨论(0)
提交回复
热议问题