1

I just created a 3D surface in MATLAB using the code below :

p = patch ( 'Vertices' , XYZ , 'Faces' , F ) ;

set ( gca , 'CLim' , [-2000 1500] ) ;

set ( p , 'FaceColor' , 'interp' , 'FaceVertexCData' , V , 'EdgeColor' , 'none' , ...

... 'CDataMapping' , 'scaled' ) ;

axis 'equal'; 
axis 'tight';
set(gca, 'YDir','normal');

where XYZ is a 352x3 matrix containing coordinates of the points of the 3D surface. F is a 700x3 matrix containing the faces which connect the points. V is a 352x1 matrix containing the values on each of the 352 points of the 3D surface.

Now this is the question : How can I plot 3D contours on the surface !!?

I've already tried contour3 function, but it requires the input matrices to be of the different dimensions than now. ( I may need to use meshgrid, but unfortunately my XYZ points are irregularly distributed. However I'm not sure whether I can do this, since I'm using the patch function. )

Please help me on this.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Omid1989
  • 121
  • 1
  • 5
  • 13

1 Answers1

1

Probably one possible solution is to perform the interpolation of your data to a regular mesh and then use contour3 function. Check the manual for TriScatteredInterp function. Briefly, you should construct the interpolant first:

F = TriScatteredInterp(XYZ(:,1), XYZ(:,2), XYZ(:,3));

Then you have to evaluate the interpolant at regular locations qx and qy (obtained with meshgrid) and get corresponding values qz:

ti = 0:0.1:10;
[qx, qy] = meshgrid(ti, ti);  
qz = F(qx, qy);

Finally, you can use contour3:

contour3(qx, qy, qz, 30);

Hope it helps.

miy
  • 306
  • 1
  • 5
  • Thanks miy. I'll try it. However, isn't there any solution for this patch !? I mean without changing the code !? – Omid1989 Feb 17 '13 at 06:48
  • AFAIU you want both surface and contour on that surface, isn't it? Then you should plot surface with your code using `patch`, and then you can plot contour using the solution which I suggested (with `contour3` function). – miy Feb 17 '13 at 08:53
  • I tried your suggested solution, but it didn't work as what I wanted to be. Any other solution !? – Omid1989 Mar 14 '13 at 06:46
  • Actually I want the contours of V over XYZ ; ( not Z over XY ! ). What should I do now !? – Omid1989 Mar 28 '13 at 13:09