Error using reshape function when trying to split columns into equally sized columns in new cell array
1 view (last 30 days)
Show older comments
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!
Accepted Answer
_
on 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);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!