converting 3d matrix into a cell array
10 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a 3D matrix (1001x 259x 259) and want to convert to a cell array (1x1001) in which each cell array has 259x259 matrix (2D matrix). Could anyone help?
Thanks.
采纳的回答
Dyuman Joshi
2024-3-22
@AT_HYZ, change the dimensions and use the above transformation -
abc = rand(1001,259,259);
%Shift dimensions
Mymatrix = shiftdim(abc, 1);
%Check size
size(Mymatrix)
%Use num2cell
Mycell = num2cell(Mymatrix,[1 2]);
size(Mycell)
%Change the size of the cell array as required
Mycell = reshape(Mycell, 1, 1001);
%Check the size of data inside a cell element
size(Mycell{1})
0 个评论
更多回答(1 个)
James Tursa
2024-3-22
编辑:James Tursa
2024-3-22
x = rand(1001,259,259);
result = arrayfun(@(k)squeeze(x(k,:,:)),1:size(x,1),'uni',false);
size(result)
size(result{1})
But, be advised that for matrix manipulation it might be better to keep this data as a 3D array with dimensions 259x259x1001 (i.e., permute(x,[2 3 1])) so that you can take advantage of the page functions like pagemtimes, pagemldivide, etc.
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!