lyan
lyan

Reputation: 71

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
============

Upvotes: 6

Views: 19109

Answers (3)

user85109
user85109

Reputation:

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)

alt text

Upvotes: 7

Marcin
Marcin

Reputation: 3524

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?

Upvotes: 0

Mikhail Poda
Mikhail Poda

Reputation: 5832

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.

Upvotes: 5

Related Questions