Tracking Min & Max Values in 2D Contour Plot

조회 수: 10 (최근 30일)
Irvin Velazquez Morales
Irvin Velazquez Morales 2024년 4월 8일
답변: DGM 2024년 4월 8일
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?

채택된 답변

DGM
DGM 2024년 4월 8일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by