3d plot-surf

8 views (last 30 days)
Reyhaneh S. Ghazanfari
Reyhaneh S. Ghazanfari on 27 Oct 2015
Answered: Image Analyst on 31 Dec 2015
Dear all,
I have a 2d matrix (2358*2) which corresponds to the points of a 2d grid (A: x-y data). These points do not define a rectangle. A second matrix (B: 2358*1) represents a specific variable corresponding to each of the gird points. What I want to show is the a 3D representation of these two matrices; so that I can get the surface of B over the grid points (A). The function 'surface' may work but I could not apply it as I do not have exactly a fully rectangle grid.
What I need to get as the end needs to look like a 3d topography.
Your great help would be appreciated, many thanks.
Reyhaneh

Accepted Answer

Mike Garrity
Mike Garrity on 27 Oct 2015
You have a couple of options. We were just discussing them in this other thread. In that case they wanted a 2D color representation, but you can use the same techniques for a 3D surface. In that case, the "pcolor" becomes "surf", and leave the "view(2)" out of the trisurf example.
  2 Comments
Reyhaneh S. Ghazanfari
Reyhaneh S. Ghazanfari on 21 Dec 2015
Hi Mike,
Many thanks for your answer.
Unfortunately, I did not get what I wanted by applying the explained approach.
Actually, I don not want to do any kind of interpolation for extra points. What I have is already a grid-based data (x,y,z) where x and y are already representing grid points. In other words I would like just to show these specific points of the grid meshgrid(x,y) with a height (as third dimension) which corresponds to z, not all the grid points with interpolated values. By plot3(x,y,z), I get the scatter representation. but I would like to get the continuous 3D surface built solely on these points, since afterwards I need to get the volume of this 3D object.
Your help would be highly appreciated, many thanks.
Reyhaneh
Mike Garrity
Mike Garrity on 31 Dec 2015
If you have X,Y,Z triplets for all of the locations in a 2D X,Y domain, then it's just a matter of getting your arrays into the right shape. I can't tell you how to do that without knowing more about the shape they're in, but it's likely to involve the reshape function.
As an example, lets say I had this data:
[x1,y1] = meshgrid(linspace(-pi,pi,10), ...
linspace(-pi,pi,7));
z1 = sin(x1).*sin(y1);
pts = [x1(:), y1(:), z1(:)];
clear x1 y1 z1
The array pts has 70 rows and 3 columns and looks something like this:
-3.1416 -3.1416 0.0000
-3.1416 -2.0944 0.0000
-3.1416 -1.0472 0.0000
-3.1416 0 0
-3.1416 1.0472 -0.0000
-3.1416 2.0944 -0.0000
-3.1416 3.1416 -0.0000
-2.4435 -3.1416 0.0000
-2.4435 -2.0944 0.5567
-2.4435 -1.0472 0.5567
...
To use it with surf, I need to get it back into the 7x10 shape of the original arrays x1,y1,z1. I can do that with reshape like so:
m = 7;
n = 10;
x2 = reshape(pts(:,1),[m n])
y2 = reshape(pts(:,2),[m n])
z2 = reshape(pts(:,3),[m n])
surf(x2,y2,z2)
But that's just an example. The details are going to depend on the order of the values. In some cases it will be more complicated than that example.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 31 Dec 2015
If your x,y locations are not complete (some coordinates are missing), or not in a perfect grid, then you'll have to get them into a grid using scatteredInterpolant(). After you use scatteredInterpolant(), then you'll have a perfect rectangular gridded image and then you can use surf to map the value into a height above a plane, or you can use imshow() to display it as an image.

Tags

Community Treasure Hunt

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

Start Hunting!