cell2mat -> operation -> mat2cell : How...?

조회 수: 15 (최근 30일)
William Thielicke
William Thielicke 2021년 8월 19일
댓글: William Thielicke 2021년 8월 19일
Hi, I have a cell aray that I need to convert to a 3D matrix, perform some operation, and then convert it back to the original cell format. I am failing to do te last step:
for i=1:301 % generate the cell array example dataset
u{1,i}=rand(41,50);
end
u_3d=reshape(cell2mat(u),size(u{1},1),size(u{1},2),size(u,2)); %convert cell array to 3D matrix
u_3d=medfilt3(u_3d); %perform an operation
u_3d=reshape(u_3d, size(u{1},1) , size(u{1},2)*size(u,2)); %reshape
% ... and convert back to cell array in original format... I don't get what
% numbers I have to enter...
bla=mat2cell(u_3d,[41 50],301); %Error
Thanks for your help!

채택된 답변

Adam Danz
Adam Danz 2021년 8월 19일
편집: Adam Danz 2021년 8월 19일
for i=1:301 % generate the cell array example dataset
u{1,i}=rand(41,50);
end
u_3d = cat(3,u{:});
u_3dFilt = medfilt3(u_3d); %perform an operation
u_cell = squeeze(num2cell(u_3dFilt, [1,2]))';
Confirm output
% check that it's a 1x301 cell
whos('u_cell')
Name Size Bytes Class Attributes u_cell 1x301 4967704 cell
% Spot-check that cell n matches u_3dFilt(:,:,n)
isequal(u_cell{10}, u_3dFilt(:,:,10))
ans = logical
1

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by