Asked by Javad
on 6 Jul 2018

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

Answer by Anton Semechko
on 6 Jul 2018

Accepted Answer

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

Javad
on 7 Jul 2018

https://www.mathworks.com/matlabcentral/fileexchange/35250-matlab-plot-gallery-wind?focused=6793015&tab=example

The above link explain it. Also, you can load it using 'load wind'. I look forward to hearing from you. Many thanks

Anton Semechko
on 8 Jul 2018

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
on 12 Jul 2018

Dear Anton

Many thanks. It works

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## James Tursa (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/409179-how-can-i-extract-the-slices-of-a-3d-matrix-in-x-direction-from-a-3d-matrix#comment_586614

## Javad (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/409179-how-can-i-extract-the-slices-of-a-3d-matrix-in-x-direction-from-a-3d-matrix#comment_586774

Sign in to comment.