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:
2d data interpolation

Subject: 2d data interpolation

From: Giuseppe

Date: 29 Nov, 2012 15:21:09

Message: 1 of 6

Hi
I have a problem with the function interp2: I have a matrx 100x3 where the first column is the x-coordinate, the second column is the y-coordinate and the third column is the value at the coordinates x and y.
I would like to interpolate those values with a grid 600x600 but the x and y coordinates are not monotonic vectors and interp2 gives me an error.

Can anyone help me?

Many thanks
Giuseppe

Subject: 2d data interpolation

From: Justin Ashmall

Date: 29 Nov, 2012 15:30:14

Message: 2 of 6

"Giuseppe" wrote in message <k97uh5$9t7$1@newscl01ah.mathworks.com>...
> Hi
> I have a problem with the function interp2: I have a matrx 100x3 where the first column is the x-coordinate, the second column is the y-coordinate and the third column is the value at the coordinates x and y.
> I would like to interpolate those values with a grid 600x600 but the x and y coordinates are not monotonic vectors and interp2 gives me an error.
>
> Can anyone help me?

Show us what you've already tried (and what doesn't work)...

Subject: 2d data interpolation

From: Giuseppe

Date: 30 Nov, 2012 07:23:15

Message: 3 of 6

Yes, sure, these are the command lines
(cen_x is the vector with the x-coordinates, cen_y with the y-coordinates and in dd there are the values I want to interpolate. All of them are vectors with the same length)

[Xi, Yi] = meshgrid(0:600);
Zi = interp2(cen_x, cen_y, dd, Xi, Yi);
figure, mesh(Xi, Yi, Zi);

When I run these lines, I have the message:

??? Error using ==> interp2 at 180
X and Y must be monotonic vectors or matrices produced by MESHGRID.

Error in ==> trial at 12
Zi = interp2(cen_x, cen_y, dd, Xi, Yi);

and I know that cen_x and cen_y are not monotonic, but they can't be monotonic because they are discrete points coming from other lines and, even if I force cen_x to be monotonic, cen_y is not like that.

Thank you again
Giuseppe

Subject: 2d data interpolation

From: Steven_Lord

Date: 30 Nov, 2012 14:37:40

Message: 4 of 6



"Giuseppe " <giuseppe.zito@artorg.unibe.ch> wrote in message
news:k99mt3$16l$1@newscl01ah.mathworks.com...
> Yes, sure, these are the command lines
> (cen_x is the vector with the x-coordinates, cen_y with the y-coordinates
> and in dd there are the values I want to interpolate. All of them are
> vectors with the same length)
>
> [Xi, Yi] = meshgrid(0:600);
> Zi = interp2(cen_x, cen_y, dd, Xi, Yi);
> figure, mesh(Xi, Yi, Zi);
>
> When I run these lines, I have the message:
>
> ??? Error using ==> interp2 at 180
> X and Y must be monotonic vectors or matrices produced by MESHGRID.

That's correct. The INTERP2 function interpolates a function whose values
are known on a regular grid to scattered points. If you want to interpolate
a function whose values are known at scattered points, look at GRIDDATA.

http://www.mathworks.com/help/matlab/ref/griddata.html

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

Subject: 2d data interpolation

From: Giuseppe

Date: 1 Dec, 2012 09:52:08

Message: 5 of 6

Yes, you're right! Now it's working!!
Many thanks for your help.

Cheers
Giuseppe

Subject: 2d data interpolation

From: fviolitta@gmail.com

Date: 24 Apr, 2013 04:24:42

Message: 6 of 6

On Saturday, December 1, 2012 1:52:08 AM UTC-8, Giuseppe wrote:
> Yes, you're right! Now it's working!!
>
> Many thanks for your help.
>
>
>
> Cheers
>
> Giuseppe

Hi, will the griddata interpolate values just like when we are using interp2? Thanks.

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