Tracking Min & Max Values in 2D Contour Plot

23 vues (au cours des 30 derniers jours)
Irvin Velazquez Morales
Irvin Velazquez Morales le 8 Avr 2024 à 2:00
Réponse apportée : DGM le 8 Avr 2024 à 3:12
Greetings everyone,
I have a matrix of 288x96 for a value changing with time in a for loop. I made an animation of the 2D contour changing with time as shown below.
I was able to plot the change of max and min over time. However, I want to be able to track where the max & min are in the 2D contour plot animation. Preferably with an X mark to show where the points are located. How can I achieve that?

Réponse acceptée

DGM
DGM le 8 Avr 2024 à 3:12
I don't know how your data is arranged or how you're plotting it, but you should be able to just use plot(). I assume you have x,y,and z data. If your x,y data are not 2D, this may require some changes. I'm going to assume that you're not using contour(), but rather imagesc() or pcolor(). That really doesn't change much anyway.
% some fake data
[X Y Z] = peaks(100);
% plot it
imagesc(X(:),Y(:),Z); hold on
% plot a marker for the global maximum
mx = max(Z(:));
mask = Z == mx;
xmx = mean(X(mask));
ymx = mean(Y(mask));
plot(xmx,ymx,'x')
% plot a marker for the global minimum
mn = min(Z(:));
mask = Z == mn;
xmn = mean(X(mask));
ymn = mean(Y(mask));
plot(xmn,ymn,'o')
Note that depending on your data, there may be more than one point where Z is maximized (or minimized). You may need to do something to resolve those cases. In this example, I assume any such duplicate points belong to the same peak, and I'm just averaging their positions. If there are multiple peaks at the same maximal value, a different approach may be warranted.

Plus de réponses (0)

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by