Reshape row wise w/ different starting/ending elements number

后端 未结 3 1936
没有蜡笔的小新
没有蜡笔的小新 2021-01-21 23:13

The problem is:

Product of known dimensions, 3, not divisible into total number of elements, 16.

this because i want to reshape a

3条回答
  •  滥情空心
    2021-01-21 23:39

    You can also pre-allocate a vector of zeroes, fill in your data for as many elements as there are in your vector, then reshape it when you're done:

    vec = 1:16; %// Example data
    numRows = 6;
    numCols = 3;
    newVec = zeros(1:numRows*numCols);
    newVec(1:numel(vec)) = vec;
    newMat = reshape(newVec, numRows, numCols);
    

提交回复
热议问题