How to plot function with conditions (3d)

4 ビュー (過去 30 日間)
Niklas Kurz
Niklas Kurz 2020 年 12 月 6 日
コメント済み: Niklas Kurz 2020 年 12 月 6 日
Suppose I want to plot the function
% f(x,y) = x.*y by saying:
[x,y] = meshgrid (-2:2:2);
z = x.*y;
surf(x,y,z)
But what if I want the x and y values also to fulfill the equation x + y <= 1 ?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 6 日
You can replace the unwanted values with nan.
[x,y] = meshgrid (-2:2:2);
z = x.*y;
mask = x + y <= 1;
z(~mask) = nan;
surf(x,y,z)
  1 件のコメント
Niklas Kurz
Niklas Kurz 2020 年 12 月 6 日
Thank you !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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