How to Convert a 3D Matrix into Cell Array of Desire Dimension
1 回表示 (過去 30 日間)
古いコメントを表示
採用された回答
Paul
2023 年 6 月 27 日
A = rand(2,100,500); % example data
C = squeeze(num2cell(A,[1 2])); % create cell array
whos C
isequal(cat(3,C{:}),A) % verify
2 件のコメント
Paul
2023 年 6 月 27 日
A = rand(500,2,100);
C = num2cell(A,[2 3]); % line 1
At this point, each elment of C is 1 x 2 x 100 and is isequal to the corresponding slice of A. For example
size(C{293})
isequal(C{293},A(293,:,:))
To make each cell 2 x 100
C = cellfun(@(c) squeeze(c),C,'UniformOutput',false); % line 2
size(C)
size(C{293})
isequal(C{293},squeeze(A(293,:,:)))
Lines 1 and 2 can be combined into a single line if desired.
There may be a better way to do this.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!