Error using reshape function when trying to split columns into equally sized columns in new cell array

1 vue (au cours des 30 derniers jours)
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 commentaires
Image Analyst
Image Analyst le 23 Jan 2022
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 le 23 Jan 2022
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!

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 23 Jan 2022
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);

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by