Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TriScatteredInterp NaN Problems

178 views
Skip to first unread message

Tyler Duff

unread,
Apr 25, 2012, 12:48:12 PM4/25/12
to
Hello,

I have 3 vectors that I need to create an interpolated surface plot of, and I'm using some of the code from the TriScatteredInterp examples. However, when I run the code, I simply get my qz matrix filled with NaNs. Why is this happening and how can I fix it? I tried using griddata, and the exact same thing happened. Any help would be appreciated!

Input:

clc
clear all
close all

x = [0.8003 0.8911 0.908 0.8785 0.8988 0.8621 0.8986 0.8135];
y = [0 6.151 7.75 7.75 8 8.62 16 16];
z = [4 0.769 0.969 3.875 4 2.15 4 12];

x = x';
y = y';
z = z';

F = TriScatteredInterp(x,y,z, 'natural');

ti = -20:.25:20;
[qx,qy] = meshgrid(ti,ti);
qz = F(qx,qy);
mesh(qx,qy,qz);
hold on;
plot3(x,y,z,'o');
hold off


This code generates that scatter, but not the mesh, because qz is just NaNs.

Thanks!

Steven_Lord

unread,
Apr 25, 2012, 1:23:09 PM4/25/12
to


"Tyler Duff" <marke...@yahoo.com> wrote in message
news:jn99sc$o23$1...@newscl01ah.mathworks.com...
> Hello,
> I have 3 vectors that I need to create an interpolated surface plot of,
> and I'm using some of the code from the TriScatteredInterp examples.
> However, when I run the code, I simply get my qz matrix filled with NaNs.
> Why is this happening and how can I fix it? I tried using griddata, and
> the exact same thing happened. Any help would be appreciated!

Look at the region for which you have data:

x = [0.8003 0.8911 0.908 0.8785 0.8988 0.8621 0.8986 0.8135];
y = [0 6.151 7.75 7.75 8 8.62 16 16];
k = convhull(x, y);
plot(x(k), y(k), 'b-');

and the region over which you're trying to interpolate:

axis([-20 20 -20 20]);

TriScatteredInterp, as the name implies, does _interpolation_ not
_extrapolation_. TriScatteredInterp will return NaN for any value outside
the convex hull of the data, which in this case is anything outside the blue
line in the figure.

*snip*

> This code generates that scatter, but not the mesh, because qz is just
> NaNs.

If you want to know the value of the surface outside that region, get more
data in the regions where you want to evaluate the surface. Otherwise you're
basically guessing, and as Mark Twain once wrote (I borrowed this quote from
John D'Errico):


"In the space of one hundred and seventy-six years the Lower Mississippi has
shortened itself two hundred and forty-two miles. That is an average of a
trifle over one mile and a third per year. Therefore, any calm person, who
is not blind or idiotic, can see that in the Old Oölitic Silurian Period,
just a million years ago next November, the Lower Mississippi River was
upward of one million three hundred thousand miles long, and stuck out over
the Gulf of Mexico like a fishing rod. And by the same token any person can
see that seven hundred and forty-two years from now the Lower Mississippi
will be only a mile and three quarters long, and Cairo and New Orleans will
have joined their streets together, and be plodding comfortably under a
single mayor and a mutual board of aldermen. There is something ascinating
about science. One gets such wholesome returns of conjecture out of such a
trifling investment of fact."

Mark Twain, Life on the Mississippi

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

0 new messages