フィルターのクリア

How to implement gradient fill based on Waterfall command?

3 ビュー (過去 30 日間)
Pengkun Shi
Pengkun Shi 2022 年 10 月 19 日
編集済み: Walter Roberson 2023 年 8 月 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
How can I write code to achieve gradient filling, so that the above figure has the rendering effect of the following figure?
Thanks a lot.

回答 (1 件)

Saffan
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:

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by