Surface/contour plot
2 views (last 30 days)
Show older comments
Hi everyone! I am new again to using MATLAB. I have a set of three-variable data that are numerically given. How will I go and generate a 3D plot/surface/contour? I need to specify the data and use any of the functions available to plot. One of the first I did was to place all the values in excel: I placed all X-values in column A, all Y-values in column B, and all Z-values in column C. I invoked xlsread to have them mapped to MATLAB. However, I dont seem to get a good plot/contour?
What seems to be wrong. The final graph does not give the correct Xs, Ys, and Zs. Please help. thanks
0 Comments
Accepted Answer
Walter Roberson
on 11 Apr 2011
Are your x and y data on a grid, or are they scattered around?
And which MATLAB version are you using?
If you do not need a surface, then scatter3() might be what you want.
More Answers (1)
John D'Errico
on 11 Apr 2011
This is a problem of scattered data. Such data, not already filling a nice uniform grid, is not directly plot-able as a surface, because MATLAB does not know how those scattered points connect together into that surface. Your eyes/brain are very good at interpreting things as a surface.
If the data does form a simple surface, that could in theory be written in the form
z = f(x,y)
then you can use tools in MATLAB to do this. One option is to generate a gridded surface, using a tool like my gridfit, as found on the file exchange.
It will create a nice smooth surface, that surf can plot, or that you can use with the contour function to do as you wish.
If perhaps you do not wish for a complete grid, perhaps if gridfit would do too much extrapolation to suit you on a strangely shaped data domain, then you can use tricontour, also found for download from the file exchange. Or, you could use delaunay to triangulate your data, and then apply trimesh, or trisurf to the result.
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!