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

2 vues (au cours des 30 derniers jours)
lil brain
lil brain le 22 Jan 2022
Commenté : lil brain le 23 Jan 2022
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):

Réponse acceptée

Walter Roberson
Walter Roberson le 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,[]);
end
end
  1 commentaire
lil brain
lil brain le 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:
"Error using reshape
Product of known dimensions, 512, not divisible into total number of elements, 23925."

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing 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