How do I resize a matrix in MATLAB?

后端 未结 3 1917
旧时难觅i
旧时难觅i 2020-11-28 16:48

Suppose I had a 1-by-12 matrix and I wanted to resize it to a 4-by-3 matrix. How could I do this?

My current solution is kind of ug

3条回答
  •  感情败类
    2020-11-28 16:53

    Try the RESHAPE function:

    A = (1-by-12 matrix);
    B = reshape(A,4,3);
    

    Note that the matrix B will be filled with elements from A in a columnwise fashion (i.e. columns will be filled from top to bottom, moving left to right).

    Example:

    >> A = 1:12;
    >> B = reshape(A,4,3)
    
    B =
    
         1     5     9
         2     6    10
         3     7    11
         4     8    12
    

提交回复
热议问题