简体   繁体   中英

Surface plot with 3 vectors Matlab

I need to be able to do a surface plot using data from 3 vectors. I found similar information, but no method seems to work with my data. My X and Y columns are evenly spaced, but not in increasing order. I tried different methods, but none of them seem to give me what I want, which is a simple surface linking close points together. I tried the following:

[X Y]=meshgrid(x,y);
Z=griddata(x,y,z, X,Y);
surf(X,Y,Z);

This is not exactly what I want, because it creates a surface at z=0 and makes it look more like a volume plot than just a surface. It also runs very slowly on my computer (probably from creating all the gridpoints). If I could get something that doesn't require as much memory it would be ideal (my vectors have about 20k values each), but this is not a necessity.

***Edit: I also tried using the scatteredInterpolant method found here ,but the function doesn't seem to be recognized by MATLAB and I get this error:

Undefined function 'scatteredInterpolant' for input arguments of type 'double'.

Also here is an image of my problem: 这里

You can see that we can't see under the surface, there is some z=0 plane blocking it.

If you have anything for me, any help is appreciated.

Thanks in advance.

**Edit 2: I added sample vectors , they're my x,y and z values from left to right.

***Edit 3: Here's an image of the triangulation I get. As you can see some points are being ignored for some reason, which gives those long and weird looking blue triangles.

Mike

If you have points which are described by vectors, and you want to plot them you could always use a Delauny triangulation. The function in matlab is called Tri=delauny(X,Y,Z) . The data generated by this function can be shown with either trimesh(Tri,X,Y,Z) or trisurf(Tri,X,Y,Z) . Keep in mind trisurf is only for 3D data. If you want to adjust the transparancy of plots in your graph use the alpha setting.

I hope this helps

As conventional methods seem to fail, I would suggest you to do it manually.

  1. Create a Z matrix full of NaN values. The size of the matrix should be dependant on your x and y values.
  2. Loop over all occuring x , y , pairs and put their (average?) z value in the right position of your Z matrix.
  3. Loop over all NaN values and interpolate their value. Perhaps using filter2 .
  4. Use surf to plot the resulting surface

To me it looks like you just need to sort your data before plotting.

Here is an example which I believe is similar to your case (since I could not download your data).

x = [2 1 4 3 -1 -3 -4 -2];
y = [1 2 3 4 -1 -2 -3 -4];
z = 32 - x.*x - y.*y;

[X1 Y1] = meshgrid(x,y);
Z1 = 32 - X1.*X1 -Y1.*Y1; 
surf(X1,Y1,Z1)

aux = sort([x;y],2);
x = aux(1,:);
y = aux(2,:);

[X2 Y2] = meshgrid(x,y);

Z2 = 32 - X.*X - Y.*Y;
figure()
surf(X2,Y2,Z2)

The first figure results in a very problematic surface: 图1(未分类图)

The second figure contains the desired surface: 图2(排序图)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM