Error using reshape function when trying to split columns into equally sized columns in new cell array
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I have a cell array (participants) with 19 cells (one cell for each participant). Within each cell there is a matrix with 21 columns (21 data points for each participant). I want to split each of the 21 columns into a list of 512 element long columns. This way each of the 21 original colums is cut into smaller columns which are then saved in a new matrix within a new cell array.
Hence each particpant has a cell array where each cell represents one of the original 21 columns. In each cell there is a matrix with 512 long columns that together make up the entirety of the original colum.
For this I have the following code:
for j = 1:numel(participants)
N = block_size*ceil(numel(participants{j},1)/block_size);
participants{j,1}(end+1:N,:) = NaN;
for k = 1:1:num_columns
p_windows{j,k} = reshape(participants{j,1}(:,k),block_size,[]);
end
end
The idea is to fill all of the uneven columns with NaNs however when running this code I get the following error:
Error using reshape
Product of known dimensions, 512, not divisible into total number of elements, 23925.
Can anyone help? It seems as though the columns are not filled with NaNs afterall? Thanks!
2 件のコメント
Image Analyst
2022 年 1 月 23 日
Make it easy for us to help you: attach participants in a .mat file
save('answers.mat', 'participants');
after reading this:
In the meantime, tell us how you plan on splitting up the column into groups of 512 rows each when it's not an integer multiple of 512:
>> 23925/512
ans =
46.728515625
It needs to be either 46 or 47. Why is it not?
採用された回答
Voss
2022 年 1 月 23 日
The N's are not being calculated correctly, because this line is incorrect:
N = block_size*ceil(numel(participants{j},1)/block_size);
It should be:
N = block_size*ceil(size(participants{j},1)/block_size);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!