Reshape column vector

前端 未结 2 653

Hello I\'m working with MATLAB and I have a \"z\" column vector that has dimension of (9680 x 1). I want to reshape it in order to have an array \"z\" of di

相关标签:
2条回答
  • 2020-12-21 06:25

    Matlab stores the matrix values in column major format (this is important during reshape). Since you want row major, you need to do

    z = reshape(z, [220 44]).';
    

    i.e. transpose afterwards.

    0 讨论(0)
  • 2020-12-21 06:36

    I'd use Andreas H.'s approach.

    As an alternative, there's a vec2mat function in the Communications Toolbox that does just that, and even fills missing values if needed:

    >> x = 11:18;
    >> vec2mat(x,4) %// no padding needed
    ans =
        11    12    13    14
        15    16    17    18
    >> vec2mat(x,5) %// padding needed; with 0 by default
    ans =
        11    12    13    14    15
        16    17    18     0     0
    >> vec2mat(x,5,-1) %// padding needed; with specified value
    ans =
        11    12    13    14    15
        16    17    18    -1    -1
    
    0 讨论(0)
提交回复
热议问题