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

조회 수: 1 (최근 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 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