3d plot-surf
조회 수: 5 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Mike Garrity
2015년 10월 27일
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
Mike Garrity
2015년 12월 31일
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.
추가 답변 (1개)
Image Analyst
2015년 12월 31일
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!