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

6 vues (au cours des 30 derniers jours)
William Thielicke
William Thielicke le 19 Août 2021
Commenté : William Thielicke le 19 Août 2021
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!

Réponse acceptée

Adam Danz
Adam Danz le 19 Août 2021
Modifié(e) : Adam Danz le 19 Août 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
  1 commentaire
William Thielicke
William Thielicke le 19 Août 2021
Great, thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by