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

3 ビュー (過去 30 日間)
lil brain
lil brain 2022 年 1 月 22 日
コメント済み: lil brain 2022 年 1 月 23 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by