Modified contour plot with different functions

I was wondering how to create a contour plot with the following specifications:
I have two variables x and y and two functions of these variables f(x,y) and g(x,y) and I want to plot f(x,y) in a contour plot. However I want to highlight those areas where g(x,y)>f(x,y). Of course I could graph something like h = g-f and see where it is positive but I think the first option is better. I would very much appreciate if someone could help me with this.

 採用された回答

KSSV
KSSV 2019 年 5 月 8 日

1 投票

[X,Y,Z] = peaks(100) ; % let this be g
idx = Z>3 & Z<5 ; % a given condition
contour(X,Y,Z)
hold on
plot(X(idx),Y(idx),'*r')

6 件のコメント

AlphaReign
AlphaReign 2019 年 5 月 8 日
I see your point, but the condition I need is based on another function, so that I can't really implement this. Any idea of how could I express that: idx = Z > F ?
Thank you very much.
KSSV
KSSV 2019 年 5 月 8 日
編集済み: KSSV 2019 年 5 月 8 日
I can't really implement this why not?
It is straighforward as I have shown the above code.
idx = Z>F ;
AlphaReign
AlphaReign 2019 年 5 月 8 日
The logical condition returns a matrix idx with 0's and 1's whereas X and Y are vectors, therefore they're out of the arrays bounds.
KSSV
KSSV 2019 年 5 月 8 日
sconvert x,y to matrices.....using meshgrid.
AlphaReign
AlphaReign 2019 年 5 月 8 日
Got it! Thank you very much :)
KSSV
KSSV 2019 年 5 月 8 日
Thanks is accepting the answer..:)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeContour Plots についてさらに検索

タグ

質問済み:

2019 年 5 月 8 日

コメント済み:

2019 年 5 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by