How to implement gradient fill based on Waterfall command?
조회 수: 3 (최근 30일)
이전 댓글 표시
Use the Waterfall command to draw a picture as shown in the following figure:
[X,Y] = meshgrid(-3:.125:3);
Z = peaks(X,Y);
C = gradient(Z);
waterfall(X,Y,Z,C)
colorbar
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161403/image.png)
How can I write code to achieve gradient filling, so that the above figure has the rendering effect of the following figure?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1161408/image.jpeg)
Thanks a lot.
댓글 수: 0
답변 (1개)
Saffan
2023년 8월 30일
Hi,
To accomplish this, you can use the “surf” method as shown in the following code snippet:
[X, Y] = meshgrid(-3:.125:3);
Z = peaks(X, Y);
% Calculate gradient
[dx, dy] = gradient(Z);
gradientMagnitude = sqrt(dx.^2 + dy.^2);
% Plot using surf
surf(X, Y, Z, gradientMagnitude, 'EdgeColor', 'none');
colormap('jet');
colorbar;
The “gradientMagnitude” is used as the color data for the surface, resulting in a gradient filling effect.
Refer to this for more information:
댓글 수: 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!