Tracking Min & Max Values in 2D Contour Plot
47 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!