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

17 次查看(过去 30 天)
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