0

I am making some surface plots. I have 3 column vectors of data which are:

(X) which is a signal length
(Y) which is corresponding RPM values
(Z) which is corresponding Mass values

What I am then doing is:

xlin = linspace(min(X),max(X),30);
ylin = linspace(min(Y),max(Y),30);
[xx,yy] = meshgrid(xlin,ylin);
zz = griddata(X,Y,Z,xx,yy,'cubic');
figure(1)
clf
hold on
surf(xx,yy,zz)

Now this usually works fine. But with a particular set of X,Y,Z which to me don't seem to be any different to normal, the resulting surface plot looks a mess because the all the "points" are joined up.

What I mean is, the last point in a row is joined by diag line to the first point of the next row and the very last point at the top right corner is connected to the very first point in the bottom left.

Example (working correctly):

enter image description here

And incorrectly:

enter image description here

  • 1
    The exmaple you posted doesnt look bad. Can you show us the bad one, not the good one? However, the most likely thing that is happening is that in some specific data `min(X)==max(X)` or something like that. It may be something different, but we need to see the bad thing, not the good one. – Ander Biguri Mar 24 '15 at 10:36
  • Added link to new image. What service is being used to place the image here? – Otispunkmeyer86 Mar 24 '15 at 10:42
  • The link does not open (empty white page), could you put the image into your question? – Daniel Mar 24 '15 at 10:43
  • Yes thanks guys that is better. I was trying to go via imgur just now but the image wouldn't show in the editor. Anyway, it seems as though there is no real problem because as stated, saving the image from the matlab viewer removes the lines. But when the surface first shows, this is what it looks like, with all the points joined. – Otispunkmeyer86 Mar 24 '15 at 10:48
  • Are you sure you are not plotting 2 things, one on top of the other? – Ander Biguri Mar 24 '15 at 10:53
  • I don't think I am no. The griddata thing should take the irregularly spaced original data and map it over the square, regular grid of xx yy and interpolate to get the zz values from Z using a cubic method. Surf then needs 3 variables to work. I just plotted a new one in a new figure and got the same effect. But again saving the image as a PNG file removes the double lines. I am thinking there is nothing wrong with the method, but there is a setting somewhere that I have forgotten. – Otispunkmeyer86 Mar 24 '15 at 11:02
  • Can you give us full code+data? I can not reproduce your errors – Ander Biguri Mar 24 '15 at 12:20

0 Answers0