how to plot 3D surface from a data file in Matlab
I have a data file with 3 columns, x, y, z and I would like to do a 3D plot to visualize the surface.
开发者_运维技巧I could have used meshgrid, but the problem is that I only have data for those y that y<=x. Is there a way to do it?
An example:
x y z ============ 1 1 0.5 2 1 0.3 2 2 1.2 3 1 1.1 3 2 8.0 3 3 1.4 ============
In many cases, a simple solution is to use trisurf. For example...
x = [1, 2, 2, 3, 3, 3];
y = [1, 1, 2, 1, 2, 3];
z = [0.5, 0.3, 1.2, 1.1, 1.8, 1.4];
tri = delaunay(x,y);
trisurf(tri,x,y,z)
You can fill the missing values deterministically, just a small script with two nested loops for both x
and y
.
Otherwise look again at the function meshgrid in the MATLAB documentation. There you see See Also
section. Not accidentally there is a function griddata listed there. That's what you need! I can also recommend gridfit which is even better.
You could fit a surface through the points you have and then graph the surface. I like to use the x2fx function to generate a full quadratic model, then use the \ operator to fit the data to the model. Do you have any idea about the underlying nature of the surface you're trying to graph? Does your data have a lot of noise? That 8.0 looks a bit out of place, is that an outlier or is that proper data?
精彩评论