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
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?
lil brain
lil brain 2022-1-23
I am planning on first filling each of the columns that arent exactly 512 in size with NaNs.
The participants file is attached. Thank you!

请先登录,再进行评论。

采纳的回答

Voss
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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by