![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/370510/image.png)
How to plot a ground surface in 3D using meshgrid?
조회 수: 15 (최근 30일)
이전 댓글 표시
I have been trying to generate a inclined surface in order to use in 3D slope stability calculations. I have an example of surface that I made manually like it is shown below.. However, I woul like to do the same using meshgrid and I could not figure out how. Once I manage to plot it then I will use that surface to locate an ellipsoid in. Thanks in advance.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/370462/image.png)
댓글 수: 0
답변 (1개)
Cris LaPierre
2020년 10월 3일
This is one way. You can use meshgrid to turn vectors into matrices with values repeated in rows and/or columns. However, only Z must be a matrix. X and Y can be vectors. So here I define the slope along X, and then use meshgrid to repeat it for all values of Y. I tried to be tricky with computing the slope but mostly succeeded in making it look more complicated than it needs to be.
x = linspace(-7,9,17);
y = linspace(-4,4,9);
low = 2.6;
high = 3.4;
step = 0.1;
flat = 4;
z = (low-flat*step):step:(high+flat*step);
z(z<low) = low;
z(z>high) = high;
[Z,~] = meshgrid(z,y);
mesh(x,y,Z,'EdgeColor','k')
grid off
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/370510/image.png)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!