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

1 次查看(过去 30 天)
Hi,
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};
end
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);
end
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,[]);
end
end
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):

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by