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

21 views (last 30 days)
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!

Accepted Answer

Adam Danz
Adam Danz on 19 Aug 2021
Edited: Adam Danz on 19 Aug 2021
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

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!