Error using reshape function when trying to split columns into equally sized columns in new cell array

조회 수: 1 (최근 30일)
Hi,
I have a cell array (participants) with 19 cells (one cell for each participant). Within each cell there is a matrix with 21 columns (21 data points for each participant). I want to split each of the 21 columns into a list of 512 element long columns. This way each of the 21 original colums is cut into smaller columns which are then saved in a new matrix within a new cell array.
Hence each particpant has a cell array where each cell represents one of the original 21 columns. In each cell there is a matrix with 512 long columns that together make up the entirety of the original colum.
For this I have the following code:
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
The idea is to fill all of the uneven columns with NaNs however when running this code I get the following error:
Error using reshape
Product of known dimensions, 512, not divisible into total number of elements, 23925.
Can anyone help? It seems as though the columns are not filled with NaNs afterall? Thanks!
  댓글 수: 2
Image Analyst
Image Analyst 2022년 1월 23일
Make it easy for us to help you: attach participants in a .mat file
save('answers.mat', 'participants');
after reading this:
In the meantime, tell us how you plan on splitting up the column into groups of 512 rows each when it's not an integer multiple of 512:
>> 23925/512
ans =
46.728515625
It needs to be either 46 or 47. Why is it not?
lil brain
lil brain 2022년 1월 23일
I am planning on first filling each of the columns that arent exactly 512 in size with NaNs.
The participants file is attached. Thank you!

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2022년 1월 23일
The N's are not being calculated correctly, because this line is incorrect:
N = block_size*ceil(numel(participants{j},1)/block_size);
It should be:
N = block_size*ceil(size(participants{j},1)/block_size);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by