Plotting function in two variables only for specified domain

4 ビュー (過去 30 日間)
Jan Schäppi
Jan Schäppi 2019 年 3 月 23 日
コメント済み: Star Strider 2019 年 3 月 23 日
I would like to plot a function in two variables, so y = f(x1,x2) only a specified domain, for example for the domain {(x1,x2) : x1+x2 < 1}, but it could be every possible domain for which one can write a boolean function to check whether (x1,x2) is in the domain. How does this work?

採用された回答

Star Strider
Star Strider 2019 年 3 月 23 日
Logical matrices can result in vector results that can be difficult to work with for surf, mesh, and similar plots that require matrix arguments rather than vectors. The easiest way to avoid these problems is to set the matrix elements that do not meet the set requirements to NaN, since NaN values do not plot.
Try this simple example:
[X1,X2] = meshgrid(-5:0.5:5);
LM = (X1 + X2) < 1;
X1(~LM) = NaN;
X2(~LM) = NaN;
Y = X1.^2 + X2.^3;
figure
mesh(X1, X2, Y)
grid on
view(60, 30)
Experiment with it with your own functions.
  2 件のコメント
Jan Schäppi
Jan Schäppi 2019 年 3 月 23 日
Perfect, thank you very much.
Star Strider
Star Strider 2019 年 3 月 23 日
As always, my pleasure.

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

その他の回答 (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