cell2mat -> operation -> mat2cell : How...?
조회 수: 6 (최근 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!
댓글 수: 0
채택된 답변
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')
% Spot-check that cell n matches u_3dFilt(:,:,n)
isequal(u_cell{10}, u_3dFilt(:,:,10))
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!