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:
griddedInterpolant with three four dimensional arrays

Subject: griddedInterpolant with three four dimensional arrays

From: Jonathan W Smith

Date: 10 Apr, 2013 16:20:07

Message: 1 of 4

Hello

The p here stands for pressure.
Array p_1 has dimension has south-north, west-east, vertical, and time dimensions.

p_2 has the same dimensions and is the same size as p_2 but has a different set of pressure data.

I want to find the pressure levels of p_1 in the p_2 array because I have another array that contains ozone (I'll call this array o3). The ozone data corresponds with p_1.

I tried the following,

new_p = griddedInterpolant(p_2, p_1, o3);

I get the following error: Error using griddedInterpolant The nubmer of input coordinate arrays does not equal the number of dimensions (NDIMS) of these arrays.

I used this function based on directions from the site http://www.mathworks.com/help/matlab/ref/griddedinterpolantclass.html
 F = griddedInterpolant(X1,X2,...,Xn,V)

Subject: griddedInterpolant with three four dimensional arrays

From: Steven_Lord

Date: 10 Apr, 2013 17:18:10

Message: 2 of 4



"Jonathan W Smith" <jwsmith9@gmail.com> wrote in message
news:kk43fn$t7s$1@newscl01ah.mathworks.com...
> Hello
>
> The p here stands for pressure.
> Array p_1 has dimension has south-north, west-east, vertical, and time
> dimensions.
>
> p_2 has the same dimensions and is the same size as p_2 but has a
> different set of pressure data.
> I want to find the pressure levels of p_1 in the p_2 array because I have
> another array that contains ozone (I'll call this array o3). The ozone
> data corresponds with p_1.

What specifically are the SIZEs of p_1, p_2, and o3?

> I tried the following,
>
> new_p = griddedInterpolant(p_2, p_1, o3);

Okay, that will work if p_2, p_1, and o3 are matrices of the same size. If
p_2 and p_1 are vectors and o3 is a matrix the same size as the matrices you
receive as output from an NDGRID call with p_2 and p_1 as input then you
need to call griddedInterpolant differently.

new_p = griddedInterpolant({p_2, p_1}, o3);

Compare:

oneten = 1:10;
[X,Y] = ndgrid(oneten, oneten);
V = X.^2 + Y.^2;
F = griddedInterpolant(X,Y,V,'cubic');
F2 = griddedInterpolant({oneten, oneten},V,'cubic');

See the third, fourth, and fifth items under Input Arguments on the page to
which you linked.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: griddedInterpolant with three four dimensional arrays

From: Jonathan W Smith

Date: 10 Apr, 2013 18:24:14

Message: 3 of 4

"Steven_Lord" <slord@mathworks.com> wrote in message <kk46sj$am9$1@newscl01ah.mathworks.com>...
>
>
> "Jonathan W Smith" <jwsmith9@gmail.com> wrote in message
> news:kk43fn$t7s$1@newscl01ah.mathworks.com...
> > Hello
> >
> > The p here stands for pressure.
> > Array p_1 has dimension has south-north, west-east, vertical, and time
> > dimensions.
> >
> > p_2 has the same dimensions and is the same size as p_2 but has a
> > different set of pressure data.
> > I want to find the pressure levels of p_1 in the p_2 array because I have
> > another array that contains ozone (I'll call this array o3). The ozone
> > data corresponds with p_1.
>
> What specifically are the SIZEs of p_1, p_2, and o3?
>
> > I tried the following,
> >
> > new_p = griddedInterpolant(p_2, p_1, o3);
>
> Okay, that will work if p_2, p_1, and o3 are matrices of the same size. If
> p_2 and p_1 are vectors and o3 is a matrix the same size as the matrices you
> receive as output from an NDGRID call with p_2 and p_1 as input then you
> need to call griddedInterpolant differently.
>
> new_p = griddedInterpolant({p_2, p_1}, o3);
>
> Compare:
>
> oneten = 1:10;
> [X,Y] = ndgrid(oneten, oneten);
> V = X.^2 + Y.^2;
> F = griddedInterpolant(X,Y,V,'cubic');
> F2 = griddedInterpolant({oneten, oneten},V,'cubic');
>
> See the third, fourth, and fifth items under Input Arguments on the page to
> which you linked.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com



Steve: Thanks for your response.

Each array is 41, 71, 8 (each array the same size). I should also clarify that each array is a 3-dimensional array and not 4.

However when I try, new_p = griddedInterpolant(p_2, p_1, o3);

I get this error:
Error using griddedInterpolant The nubmer of input coordinate arrays does not equal the number of dimensions (NDIMS) of these arrays.

What am I missing?
Jonathan

Subject: griddedInterpolant with three four dimensional arrays

From: Steven_Lord

Date: 10 Apr, 2013 19:34:03

Message: 4 of 4



"Jonathan W Smith" <jwsmith9@gmail.com> wrote in message
news:kk4aoe$np2$1@newscl01ah.mathworks.com...
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <kk46sj$am9$1@newscl01ah.mathworks.com>...
>>
>>
>> "Jonathan W Smith" <jwsmith9@gmail.com> wrote in message
>> news:kk43fn$t7s$1@newscl01ah.mathworks.com...
>> > Hello
>> >
>> > The p here stands for pressure.
>> > Array p_1 has dimension has south-north, west-east, vertical, and time
>> > dimensions.
>> >
>> > p_2 has the same dimensions and is the same size as p_2 but has a
>> > different set of pressure data.
>> > I want to find the pressure levels of p_1 in the p_2 array because I
>> > have another array that contains ozone (I'll call this array o3). The
>> > ozone data corresponds with p_1.
>>
>> What specifically are the SIZEs of p_1, p_2, and o3?
>>
>> > I tried the following,
>> >
>> > new_p = griddedInterpolant(p_2, p_1, o3);
>>
>> Okay, that will work if p_2, p_1, and o3 are matrices of the same size.
>> If p_2 and p_1 are vectors and o3 is a matrix the same size as the
>> matrices you receive as output from an NDGRID call with p_2 and p_1 as
>> input then you need to call griddedInterpolant differently.
>>
>> new_p = griddedInterpolant({p_2, p_1}, o3);
>>
>> Compare:
>>
>> oneten = 1:10;
>> [X,Y] = ndgrid(oneten, oneten);
>> V = X.^2 + Y.^2;
>> F = griddedInterpolant(X,Y,V,'cubic');
>> F2 = griddedInterpolant({oneten, oneten},V,'cubic');
>>
>> See the third, fourth, and fifth items under Input Arguments on the page
>> to which you linked.
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>> To contact Technical Support use the Contact Us link on
>> http://www.mathworks.com
>
>
>
> Steve: Thanks for your response.
>
> Each array is 41, 71, 8 (each array the same size). I should also clarify
> that each array is a 3-dimensional array and not 4.
>
> However when I try, new_p = griddedInterpolant(p_2, p_1, o3);
> I get this error: Error using griddedInterpolant The nubmer of input
> coordinate arrays does not equal the number of dimensions (NDIMS) of these
> arrays.
>
> What am I missing?

If you want to do 3-D interpolation, you need either three 3-D arrays of
coordinates (the full grid representation) and a fourth 3-D array of
"function" values or a cell array of three vectors of coordinates (the grid
vectors) and a 3-D array of "function" values. If I wanted to do 3-D
interpolation in the example I wrote above (modified slightly from the
griddedInterpolant documentation) I'd need not only to make X, Y, and V
3-dimensional but I'd also need to provide a 3-D array of Z coordinates.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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