Borrar filtros
Borrar filtros

Tracking Min & Max Values in 2D Contour Plot

23 visualizaciones (últimos 30 días)
Irvin Velazquez Morales
Irvin Velazquez Morales el 8 de Abr. de 2024 a las 2:00
Respondida: DGM el 8 de Abr. de 2024 a las 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?

Respuesta aceptada

DGM
DGM el 8 de Abr. de 2024 a las 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.

Más respuestas (0)

Categorías

Más información sobre Contour Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by