Matlab 如何从N-D矩阵中提取3D矩阵?
我正在处理5D矩阵,配置如下:Matlab 如何从N-D矩阵中提取3D矩阵?,matlab,matrix,Matlab,Matrix,我正在处理5D矩阵,配置如下: [nf,nx,ny,np,nz]=size(D); 这样 我需要从这个5D矩阵D中提取两个矩阵: 第一A,例如[nf,nx,ny]=大小(A) 第二个B,例如[nf,np,nz]=大小(B) 是否有任何MATLAB代码从D提取这两个矩阵?为此,您需要为两个维度选择特定的下标索引值,从中提取数据,然后根据需要使用函数折叠长度为1的结果维度。下面是它对A和B的工作原理: pIndex = 2; % Second index of dimension 4 zIn
[nf,nx,ny,np,nz]=size(D);
这样
我需要从这个5D矩阵D中提取两个矩阵:
- 第一
,例如A
[nf,nx,ny]=大小(A)代码>
- 第二个
,例如B
[nf,np,nz]=大小(B)代码>
是否有任何MATLAB代码从
D
提取这两个矩阵?为此,您需要为两个维度选择特定的下标索引值,从中提取数据,然后根据需要使用函数折叠长度为1的结果维度。下面是它对A
和B
的工作原理:
pIndex = 2; % Second index of dimension 4
zIndex = 3; % Third index of dimension 5
A = D(:, :, :, pIndex, zIndex); % Don't need squeeze because they
% are the trailing dimensions
xIndex = 1; % First index of dimension 2
yIndex = 12; % Last index of dimension 3
B = squeeze(D(:, xIndex, yIndex, :, :));
请注意,使用a作为索引将包括该维度的所有下标。通过简单索引可以获得a的144种可能性和B的144种可能性。你在找哪一个?亲爱的疯狂物理学家,我需要一个能让我提取B和a的代码,不管有什么可能,但不改变数据的性质。谢谢如果你想在棋盘上提取一个方块,你必须选择一个方块,例如C5。您的代码无法猜测。谢谢亲爱的回答。它工作得和我预期的一样好。谢谢!@雅宝:很乐意帮忙。别忘了,你可以把答案标记为它解决了你的问题。
pIndex = 2; % Second index of dimension 4
zIndex = 3; % Third index of dimension 5
A = D(:, :, :, pIndex, zIndex); % Don't need squeeze because they
% are the trailing dimensions
xIndex = 1; % First index of dimension 2
yIndex = 12; % Last index of dimension 3
B = squeeze(D(:, xIndex, yIndex, :, :));