How can I reshape single column vector list into equally sized matrix columns
1 ビュー (過去 30 日間)
I have a single column vector variable with a list of 26599 elements. I want to reshape this list into a matrix of equally sized columns of 512. The issue is that the number 26599 isn't divisible by 512 and so I get an error. Hence, I want to reshape the vector into matrix colums where all columns have the size of 512 except for the last one.
How would I go about doing this?
I tried the reshape function but that didnt work because of the issue mentioned above.
>> R = reshape(sample_test,512,);
Error using reshape
Product of known dimensions, 512, not divisible into total number of elements, 26599.
_ 2022 年 1 月 9 日
You can't have a matrix with different size columns, but you could fill the last column with NaNs:
sample_test = ones(520,1);
% append NaNs to sample_test up to the next multiple of block_size
block_size = 512;
N = block_size*ceil(numel(sample_test)/block_size);
sample_test(end+1:N) = NaN;
R = reshape(sample_test,512,)