Error using reshape when creating a new cell array in a loop

2 views (last 30 days)
I have a cell array with 19 cells. Within each cell there is a matrix with 21 columns. Now I want to loop a piece of code over each of these columns within these matrices, for each of the cells.
When I run my code I get the error,
"Error using reshape
Product of known dimensions, 512, not divisible into total number of elements, 1108758."
This is the code:
[file_list, path_n] = uigetfile('.csv', 'Grab csv', 'Multiselect', 'on');
if ~iscell(file_list)
file_list = {file_list};
participants = cell(length(file_list),1);
for i = 1:length(file_list)
filename = file_list{i};
data_in = readmatrix([path_n, filename]);
participants{i} = data_in(:,7:27);
num_cells = size(participants);
num_columns = size(participants{i},2);
block_size = 512;
p_windows = {};
for j = 1:1:num_cells
for k = 1:1:num_columns
N = block_size*ceil(numel(participants{i},1)/block_size);
participants{i,1}(end+1:N) = NaN;
p_windows = reshape(participants{i,1},512,[]);
My goal is to take each individual column from the matrices in participants and cut them into smaller 512 element long lists. These 512 long lists are then stored in matrices (one matrix per cut-up column) and saved in a new cell array (p_windows).
I hope this makes sense. Thanks in advance!
EDIT: Here is the variable participants (19x1 cell array with matrices in it) as a download link from weshare (it was too big to upload):

Accepted Answer

Walter Roberson
Walter Roberson on 23 Jan 2022
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,[]);
  1 Comment
lil brain
lil brain on 23 Jan 2022
Hi Walter,
thanks for the reply!
However, I am getting the same error. Just this time with a different matrix I presume.
"Error using reshape
Product of known dimensions, 512, not divisible into total number of elements, 23925."

Sign in to comment.

More Answers (0)


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by