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.

 Réponse acceptée

KSSV
KSSV le 8 Mai 2019
[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 commentaires

AlphaReign
AlphaReign le 8 Mai 2019
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 le 8 Mai 2019
Modifié(e) : KSSV le 8 Mai 2019
I can't really implement this why not?
It is straighforward as I have shown the above code.
idx = Z>F ;
AlphaReign
AlphaReign le 8 Mai 2019
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 le 8 Mai 2019
sconvert x,y to matrices.....using meshgrid.
AlphaReign
AlphaReign le 8 Mai 2019
Got it! Thank you very much :)
KSSV
KSSV le 8 Mai 2019
Thanks is accepting the answer..:)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Contour Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by