Surface/contour plot

2 views (last 30 days)
Bry S
Bry S on 11 Apr 2011
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

Accepted Answer

Walter Roberson
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.
  2 Comments
Bry S
Bry S on 12 Apr 2011
I need to have a contour or a surface plot as a final output. My x and y data are equally spaced from each other with a corresponding z value for each x and y (if this is what is meant by x and y data on a grid). Please help. thanks very much.
Walter Roberson
Walter Roberson on 12 Apr 2011
surf(x,y,z)

Sign in to comment.

More Answers (1)

John D'Errico
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.
  1 Comment
Bry S
Bry S on 12 Jun 2011
Hi there! Your suggestion on how to generate 3D surface plots with scattered data fits best to my problem. However, I do not know the steps for me to be able to place the function to the Matlab 7.8.0 I am using.
How to go about placing the gridfit function to my computer? Please provide me the necessary steps from what file to place and where to place so that I can use gridfit. Thanks

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!