How can I extract the slices of a 3D matrix in x-direction from a 3D matrix?

35 ビュー (過去 30 日間)
Javad
Javad 2018 年 7 月 6 日
コメント済み: Javad 2018 年 7 月 12 日
I have a 3D matrix, which is a model of the porous media of a rock. I want to extract three 3D matrices from it so that each contains the 2D slices in a specific direction, for example x. To be clear, the matrix x contains the 2D slices in x direction, y in y-direction and z in the z-direction. I appreciate any hint or help to solve my issue.
Regards
  2 件のコメント
James Tursa
James Tursa 2018 年 7 月 6 日
It is unclear what you want. The original 3D matrix already has 2D slices in each direction that you can get at with indexing. E.g.,
xyz = original 3D matrix
k = whatever
xyz(k,:,:) --> k'th slice along x direction
xyz(:,k,:) --> k'th slice along y direction
xyz(:,:,k) --> k'th slice along z direction
Do you mean you want to permute the data so the slices are always in the first two dimensions? Or ...?
Javad
Javad 2018 年 7 月 7 日
Dear James First, thanks for your answer. But I think my question was not clear. To be clear I explain more. I have 3D matrix, which is in fact a digital rock model. All the arrays of the matrix are 0 or 1. I want to draw the streamlines in it using the command 'streamline'. But this command need x, y, z. I want to extract these three matrices from my 3D matrix. Can you help me in this regard? Thanks

サインインしてコメントする。

採用された回答

Anton Semechko
Anton Semechko 2018 年 7 月 6 日
Suppose you have G, which is a Y-by-X-by-Z 3D array, then
i-th xy slice:
G_yx=G(:,:,i); % Y-by-X array
i-th xz slice:
G_xz=permute(G(i,:,:),[2 3 1]); % X-by-Z array
i-th yz slice:
G_yz=permute(G(:,i,:),[1 3 2]); % Y-by-Z array
  5 件のコメント
Anton Semechko
Anton Semechko 2018 年 7 月 8 日
編集済み: Anton Semechko 2018 年 7 月 8 日
I see. Let's say G is your Ny-by-Nx-by-Nz 3D image and [dx,dy,dz] are dimensions of a single voxel. To get get (x,y,z) coordinates of the voxels do:
[Ny,Nx,Nz]=size(G);
[x,y,z]=meshgrid((1:Nx)*dx,(1:Ny)*dy,(1:Nz)*dz);
The variables 'x', 'y', and 'z' have the same dimensions as G, and can be used as input to the 'isosurface' function along with G to extract a triangular mesh of the level-set surface G==1.
Javad
Javad 2018 年 7 月 12 日
Dear Anton
Many thanks. It works

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScalar Volume Data についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by