Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Volume data interpolation

Subject: Volume data interpolation

From: Anna

Date: 11 May, 2012 18:51:32

Message: 1 of 7

Hello,
I'd like to perform interpolation of scalar data Vr specified in 3D non-uniformly spaced points Xr, where Xr has size [3,n_points]. But TriScatteredInterp suits me badly, since function V = F(X) fits the surfice and I need to fit the volume, e.i. to interpolate data from Xr onto uniform grid constructed with meshgrid function.
Thank you in advance,
Anna.

Subject: Volume data interpolation

From: Matt J

Date: 11 May, 2012 19:04:13

Message: 2 of 7

"Anna" wrote in message <jojn3k$7br$1@newscl01ah.mathworks.com>...
> Hello,
> I'd like to perform interpolation of scalar data Vr specified in 3D non-uniformly spaced points Xr, where Xr has size [3,n_points]. But TriScatteredInterp suits me badly, since function V = F(X) fits the surfice and I need to fit the volume, e.i. to interpolate data from Xr onto uniform grid constructed with meshgrid function.
===============

Then INTERP3 ?

Subject: Volume data interpolation

From: Anna

Date: 13 May, 2012 08:41:07

Message: 3 of 7

"Matt J" wrote in message <jojnrd$ag1$1@newscl01ah.mathworks.com>...
> "Anna" wrote in message <jojn3k$7br$1@newscl01ah.mathworks.com>...
> > Hello,
> > I'd like to perform interpolation of scalar data Vr specified in 3D non-uniformly spaced points Xr, where Xr has size [3,n_points]. But TriScatteredInterp suits me badly, since function V = F(X) fits the surfice and I need to fit the volume, e.i. to interpolate data from Xr onto uniform grid constructed with meshgrid function.
> ===============
>
> Then INTERP3 ?

Yes, it sounds logical and I've tried it out. Could you advise how to correct a mistake? The code was following (v is matrix [3,n_points])

 R1=0.5;%radius of the tube;
 phi=0:0.05:(pi/2);
 theta=0:0.05:(pi/2);
 rho=0.1:0.05:R1;
 xx=reshape(Xr(1,:),numel(phi),numel(rho),numel(theta));
 yy=reshape(Xr(2,:),numel(phi),numel(rho),numel(theta));
 zz=reshape(Xr(3,:),numel(phi),numel(rho),numel(theta));
 w=reshape(v,numel(phi),numel(rho),numel(theta));
 xlim=linspace(min(Xr(1,:)),max(Xr(1,:)),100);
 ylim=linspace(min(Xr(2,:)),max(Xr(2,:)),100);
 zlim=linspace(min(Xr(3,:)),max(Xr(3,:)),100);
 [X,Y,Z]=meshgrid(xlim,ylim,zlim);
 vi=interp3(xx,yy,zz,w,X,Y,Z);

MATLAB produces error
 Error using ==> interp3 at 138
X, Y and Z must be matrices produced by MESHGRID. Use TriScatteredInterp instead
of INTERP3 for scattered data.

Subject: Volume data interpolation

From: Anna

Date: 13 May, 2012 08:46:09

Message: 4 of 7

"Matt J" wrote in message <jojnrd$ag1$1@newscl01ah.mathworks.com>...
> "Anna" wrote in message <jojn3k$7br$1@newscl01ah.mathworks.com>...
> > Hello,
> > I'd like to perform interpolation of scalar data Vr specified in 3D non-uniformly spaced points Xr, where Xr has size [3,n_points]. But TriScatteredInterp suits me badly, since function V = F(X) fits the surfice and I need to fit the volume, e.i. to interpolate data from Xr onto uniform grid constructed with meshgrid function.
> ===============
>
> Then INTERP3 ?

Yes, thank you. Could you advise on how to correct following error. Here v is [1,n_points] vector. The code was:
 
R1=0.5;%radius of the tube;
phi=0:0.05:(pi/2);
theta=0:0.05:(pi/2);
rho=0.1:0.05:R1;
xx=reshape(Xr(1,:),numel(phi),numel(rho),numel(theta));
 yy=reshape(Xr(2,:),numel(phi),numel(rho),numel(theta));
 zz=reshape(Xr(3,:),numel(phi),numel(rho),numel(theta));
w=reshape(v,numel(phi),numel(rho),numel(theta));
 xlim=linspace(min(Xr(1,:)),max(Xr(1,:)),100);
 ylim=linspace(min(Xr(2,:)),max(Xr(2,:)),100);
 zlim=linspace(min(Xr(3,:)),max(Xr(3,:)),100);
[X,Y,Z]=meshgrid(xlim,ylim,zlim);
vi=interp3(xx,yy,zz,w,X,Y,Z);

and MATLAB produces error:

 Error using ==> interp3 at 138
X, Y and Z must be matrices produced by MESHGRID. Use TriScatteredInterp instead
of INTERP3 for scattered data.

Subject: Volume data interpolation

From: Anna

Date: 13 May, 2012 08:50:08

Message: 5 of 7

"Matt J" wrote in message <jojnrd$ag1$1@newscl01ah.mathworks.com>...
> "Anna" wrote in message <jojn3k$7br$1@newscl01ah.mathworks.com>...
> > Hello,
> > I'd like to perform interpolation of scalar data Vr specified in 3D non-uniformly spaced points Xr, where Xr has size [3,n_points]. But TriScatteredInterp suits me badly, since function V = F(X) fits the surfice and I need to fit the volume, e.i. to interpolate data from Xr onto uniform grid constructed with meshgrid function.
> ===============
>
> Then INTERP3 ?

Sorry, v is [1,n_points] vector.

Subject: Volume data interpolation

From: Bruno Luong

Date: 13 May, 2012 09:36:09

Message: 6 of 7

Xr=rand(3,1000);
Vr=rand(1,1000);

F=TriScatteredInterp(Xr',Vr(:));
[X Y Z]=ndgrid(linspace(0,1,10),linspace(0,1,10),linspace(0,1,10));

F(X,Y,Z)

% Bruno

Subject: Volume data interpolation

From: Jonathan W Smith

Date: 15 Apr, 2013 14:03:05

Message: 7 of 7

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jonva9$k2a$1@newscl01ah.mathworks.com>...
> Xr=rand(3,1000);
> Vr=rand(1,1000);
>
> F=TriScatteredInterp(Xr',Vr(:));
> [X Y Z]=ndgrid(linspace(0,1,10),linspace(0,1,10),linspace(0,1,10));
>
> F(X,Y,Z)
>
> % Bruno

How can the interpolation be done in the case that X Y Z are all arrays each having 3 dimensions? I have set up interp3 similarly to Anna, with V, Y, Z being 3-D arrays, but the end result is an 3 dimensional array with all NaNs.

Each array is 41 by 71 x 8 (lat, lon, and height).

The first array contains ozone data.
The 2nd array is are the changing vertical levels corresponding with the iozone data.
The 3rd array contains pressure levels for a different set of ozone data.

I want to interpolate the first array onto the 3rd array, being mindful of two things 1) in the 2nd array there is a different pressure for each array grid cell (decreasing with height in the 3rd dimension and 2) that in the 3rd array the pressure is only different for each of the 8 layer , in other words its the same horizontally across the array grid for an individual layer.

Thanks
Jonathan

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us