# bug #51624: griddata example fails

 Submitted by: Steve Hageman Submitted on: Mon 31 Jul 2017 04:15:12 AM UTC Category: None Severity: 3 - Normal Priority: 5 - Normal Item Group: None Status: Works For Me Assigned to: None Originator Name: LostInSpace Open/Closed: Closed Release: 4.2.0 Operating System: Microsoft Windows

You are not logged in

## Discussion

Tue 01 Aug 2017 05:10:15 PM UTC, comment #9:

PNG screen shot for last post...

Dan Sebald <sebald>
Tue 01 Aug 2017 05:08:43 PM UTC, comment #8:

I'm still a bit curious as to why the following example, which only adds the four points at the corners, results in the attached reconstructed surface:

rand ("state", 1);
x = 2*rand (1000,1) - 1;
y = 2*rand (size (x)) - 1;
x = [x; 1; 1; -1; -1];
y = [y; 1; -1; -1; 1];
z = sin (2*(x.^2+y.^2));
[xx,yy] = meshgrid (linspace (-1,1,32));
zz = griddata (x, y, z, xx, yy);
mesh (xx, yy, zz);

I can imagine that the algorithm somehow fills in those side surfaces by assuming continuity between those corner points and all the points along the arches at x=1, at y=1, etc.  But I'm wondering if that is something it should be doing under the circumstances.  When there are none of the four corners, things look reasonable.  Implicit in that statement of "reasonable" is that the reconstructed surface has a certain degree of smoothness, i.e., that it can't make drastic, high-order transitions between sample points.  Experiment with the above data with:

zz = griddata (x, y, z, xx, yy);
mesh (xx, yy, zz);

zz = griddata (x, y, z, xx, yy, "nearest");
mesh (xx, yy, zz);

zz = griddata (x, y, z, xx, yy, "cubic");
mesh (xx, yy, zz);

Dan Sebald <sebald>
Tue 01 Aug 2017 04:41:28 PM UTC, comment #7:

Seems that this has been resolved.  Closing report.

Rik <rik5>
Tue 01 Aug 2017 04:37:39 AM UTC, comment #6:

The NaN appear, I assume, because the griddata routine uses interpolation to establish the values at the mesh points.  Because the rand() routine doesn't produce any values at -1 and 1, but with minuscule likelihood, no values can be assigned to the outer mesh points.

Out of curiosity, I added such points:

rand ("state", 1);
x = 2*rand (1000,1) - 1;
x = [x; 1; 1; -1; -1];
y = 2*rand (size (x)) - 1;
y = [y; 1; -1; -1; 1];
z = sin (2*(x.^2+y.^2));
[xx,yy] = meshgrid (linspace (-1,1,32));
zz = griddata (x, y, z, xx, yy);
mesh (xx, yy, zz);

That makes griddata produce non-NAN values at the extreme, but I'm not quite sure why it is creating the surface it is, i.e., extending the edges down to -0.7568025 everywhere.  Perhaps that is because it's linear.  But it looks like "cubic" isn't implemented.  "nearest" interpolation of course won't have such side panels filled in, but it looks rather crude.

Dan Sebald <sebald>
Tue 01 Aug 2017 03:33:24 AM UTC, comment #5:

OK, pilot error I get a plot now. I had a path error and the GUI display of the 32x32 matrix threw me off because it showed Nan's, but when I printed the matrix out it only has Nan's on the corners, inside it is full of values that get plotted.

Thanks for the help, sorry for posting this as a bug. I'll go crawl back under my rock now.  ;-)

Steve Hageman <lostinspace>
Tue 01 Aug 2017 12:33:31 AM UTC, comment #4:

Thanks all for the verification - I checked "type meshgrid" and the path is correct.

C:\Octave\Octave-4.2.0\share\octave\4.2.0\m\plot\util\me
shgrid.m

Stand by while I single step the function to see what's up.

Steve Hageman <lostinspace>
Mon 31 Jul 2017 11:38:27 PM UTC, comment #3:

The example works fine for me too.  Tested on a Linux machine and on a Windows XP virtual machine (both with version 4.2.0).

It's possible the install was corrupted.  In any case, try going line by line and inspecting the intermediate results until you find which line is causing the failure.

Rik <rik5>
Mon 31 Jul 2017 05:18:31 PM UTC, comment #2:

Works here too on a linux machine.  Could you give a bit more detail about results by exploring various things?  For example, I assume that linspace (-1,1,32) looks correct (i.e., a vector of 32 samples running from -1 to 1), as you mention that yy is bad but no mention of xx.  What are the dimensions of xx and yy?

linspace is a built-in routine, but meshgrid() is a script file.  Could you "type meshgrid" to see that the path at the top of the printout is a directory you think it should be and that there isn't some old version of the script floating about on your system?  Please run "test meshgrid".  If there are failures, please post your version here.

Dan Sebald <sebald>
Mon 31 Jul 2017 10:27:53 AM UTC, comment #1:

Works ok for me.
ubuntu 16.04
octave stable latest
graphics toolkit is qt

Doug Stewart <dastew>
Mon 31 Jul 2017 04:15:12 AM UTC, original submission:

This example fails,

rand ("state", 1);
x = 2*rand (1000,1) - 1;
y = 2*rand (size (x)) - 1;
z = sin (2*(x.^2+y.^2));
[xx,yy] = meshgrid (linspace (-1,1,32));
zz = griddata (x, y, z, xx, yy);
mesh (xx, yy, zz);

The example is from help page at: http://www.gnu.org/software/octave/doc/interpreter/Interpolation-on-Scattered-Data.html

After running that example: 'yy' looks wrong it contains only -1,-1,-1,-1....

And 'zz' is definitely wrong it contains NaN's...

Command window shows no errors.

Windows 7 x64 / Octage 4.2.0 from the GNU Installer.

Steve Hageman <lostinspace>

## Attached Files

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Comment:

## Dependencies

Depends on the following items: None found

Items that depend on this one: None found

Carbon-Copy List
• -email is unavailable- added by rik5 (Posted a comment)
• -email is unavailable- added by sebald (Posted a comment)
• -email is unavailable- added by dastew (Posted a comment)
• -email is unavailable- added by lostinspace (Submitted the item)
• -email is unavailable- added by lostinspace (Octave griddata bug report)
•

Do you think this task is very important?
This task has 0 encouragements so far.

Only project members can vote.