Clear Filters
Clear Filters

Tracking Min & Max Values in 2D Contour Plot

34 views (last 30 days)
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?

Accepted Answer

DGM
DGM on 8 Apr 2024
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.

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!