Plotting a surface or mesh

1 view (last 30 days)
xy z
xy z on 21 Oct 2015
Commented: Star Strider on 21 Oct 2015
hi guys, im new and need matlab for illustrating certain things, easy question therefore
how do i plot these vectors in a three dimensional surface?
x1 = 2,4,6
x2 = 2,4,4,
x3 = 0.1,0.3,0.5
i can do this, but its not working propery, its just giving me points, no surface:
ti = 0:.1:1;
[XI,YI] = meshgrid(ti,ti);
ZI = griddata(x,y,z,XI,YI);
mesh(XI,YI,ZI), hold;
plot3(x,y,z,'o'), hold off
thank you very much, because this is not working : F = TriScatteredInterp(x,y,z);
  2 Comments
Star Strider
Star Strider on 21 Oct 2015
I can’t run your code. What are x,y,z here and in the plot call?
ZI = griddata(x,y,z,XI,YI);
xy z
xy z on 21 Oct 2015
Edited: xy z on 21 Oct 2015
Hi, thanks for your time. it was just arbitrary use for example x = [2,4,6] y = [2,4,4], z = [0.1,0.3,0.5]
the problem ist, that it only gives me the points via plot3 command, but not the surface, also delaunay doesnt fit it well
*EDIT just saw your latter post, ill check it first

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 21 Oct 2015
Edited: Star Strider on 21 Oct 2015
This sort of works (it runs and produces an interpolated surface):
x1 = [2,4,6];
x2 = [2,4,4];
x3 = [0.1,0.3,0.5];
x = x1; y = x2; z = x3; % Assumption
xi = [2:0.1:6];
yi = [2:0.1:4];
[XI,YI] = meshgrid(xi,yi); % Interpolation Grid Must Match Data Range
ZI = griddata(x,y,z,XI,YI);
mesh(XI,YI,ZI), hold;
plot3(x,y,z,'o'), hold off
The griddata function does not allow extrapolation (extrapolation is not mentioned in the documentation), so asking it to do so produces a matrix of NaN values, and NaN values do not plot. This was the reason you were not getting any surface plotted. The scatteredInterpolant class allows extrapolation, so consider using it if you want to extrapolate.
  4 Comments
xy z
xy z on 21 Oct 2015
thanks a lot, it worked fine.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!