# How to interpolate 3-D data from a .mat file?

4 views (last 30 days)
spider_plantt on 4 Aug 2020
Answered: Raunak Gupta on 12 Aug 2020
I have a 256x256x256 struct in a .mat file that I'm trying to interpolate using meshgrid and interp3. What I'm trying to do is slice the 3-D image so that it re-interpolates onto a given grid. My code is below and since I'm very new to this I'm essentially rehashing the interp3 example code. I keep getting an error right now on line 2 [X,Y,Z,V]=load('gm.mat'), reading "Insufficient number of outputs from right hand side of equal sign to satisfy assignment".
[X,Y,Z,V]=sphere;
[Xq,Yq,Zq]=meshgrid(29:9:141,29:9:141,29:9:141);
Vq=interp3(X,Y,Z,V,Xq,Yq,Zq);
figure
slice(Xq,Yq,Zq,V,120,85,120);
##### 2 CommentsShowHide 1 older comment
spider_plantt on 4 Aug 2020
Can you clarify this error? It keeps cropping up.
Insufficient number of outputs from right hand side of equal sign to satisfy
assignment.

Raunak Gupta on 12 Aug 2020
Hi,
From the question I understand you have the V data that is stored in the struct file as this is a 3D Image so only values will be stored of a particular (x,y,z) pixel. I think you need to know what the resolution of image is, like what is the spacing between adjacent pixel in each dimension. In that way you can construct the coordinates matrices X, Y, Z with that spacing using meshgrid.
If you see the example mentioned in the interp3 , the [X, Y, Z, V] = flow (10) return coordinate space in X, Y, Z and volume data in Z. All the matrices have same size.
So, you can probably create X,Y,Z as you created the Xq,Yq,Zq but with the actual spacing in the image dimesion between pixels. If you don’t know the spacing, then second syntax of interp3 mentioned here can also help.
Hope this clarifies!

### Categories

Find more on Interpolation in Help Center and File Exchange

R2018b

### Community Treasure Hunt

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

Start Hunting!

Translated by