Plotting a surface or mesh
1 view (last 30 days)
Show older comments
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
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);
Accepted Answer
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
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!