简体   繁体   English

Matlab:修改3D单元矩阵的每个立方体

[英]Matlab: modify each cube of 3D cell matrix

I have used mat2cell to create a 12 x 13 x 5 cell matrix where each cell contains a 29 x 29 x 29 cube. 我使用mat2cell创建了一个12 x 13 x 5的单元格矩阵,其中每个单元格包含一个29 x 29 x 29的立方体。 How do I generate a new 3D cell matrix containing only the central 21 x 21 x 21 cube of each 29 x 29 x 29 cube? 如何生成仅包含每个29 x 29 x 29立方体的中心21 x 21 x 21立方体的新3D单元矩阵? ie so the new matrix is still 12 x 13 x 5 but each one contains a 21 x 21 x 21 of central voxels of original cube? 也就是说,因此新矩阵仍然是12 x 13 x 5,但每个矩阵都包含21 x 21 x 21原始立方体的中央体素?

To crop an indivual block, you can use a simple indexing expression: 要裁剪单个块,可以使用一个简单的索引表达式:

c=4 % cut of c rows on each side.
for ix=1:numel(X)
   X{ix}=X{ix}(1+c:end-c,1+c:end-c,1+c:end-c);
end

If you are aiming for a solution with a better Performance, I recommend switching to multi dimensional matrices: 如果您希望获得性能更好的解决方案,建议您切换到多维矩阵:

c=4
Y=reshape(X,29,12,29,13,29,5);
%now the first block is squeeze(Y(:,1,:,1,:,1))
%now cut to smaller blocks:
Y=Y(1+c:end-c,:,1+c:end-c,:,1+c:end-c,:);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM