How to plot over a range using absolute value

7 ビュー (過去 30 日間)
Elizabeth Lu
Elizabeth Lu 2019 年 11 月 12 日
コメント済み: Elizabeth Lu 2019 年 11 月 12 日
I'm trying to plot a surface over a square given by the function abs(x) + abs (y) 2. I'm trying to use meshgrid, but I'm lost on what I should use as my intervals. If someone could lead me in the right direction, that would be awesome.

採用された回答

the cyclist
the cyclist 2019 年 11 月 12 日
編集済み: the cyclist 2019 年 11 月 12 日
One way to do it would be to create a grid that is larger than the one you need, but then overwrite the x-y grid values that do not obey the restriction into NaN. For example:
x = linspace(-2,2,100);
y = linspace(-2,2,100);
[xx,yy] = meshgrid(x,y);
idxToRemove = (abs(xx) + abs (yy) > 2);
xx(idxToRemove) = NaN;
yy(idxToRemove) = NaN;
zz = xx - yy.^2;
figure
mesh(xx,yy,zz)
Screen Shot 2019-11-12 at 5.35.14 PM.png
  1 件のコメント
Elizabeth Lu
Elizabeth Lu 2019 年 11 月 12 日
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