How to plot the highest y values for each x value for a figure with multiple plots
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a figure with 9 graphs plotted in it. Each line was plotted in one iteration of a loop, so, as I run my code, I don't conserve x nor y values. Instead, new ones are generated. Is it possible to plot a single line that has the highest y value for each x value? Here's an example of the type of graph I have in mind

0 comentarios
Respuestas (1)
Fangjun Jiang
el 20 de Jul. de 2018
I would recommend you saving the data for each line when it is created running the loop. If not possible, you could get the data from the figure by going through its children and the 'XData' and 'YData'. Here is an example
f=figure;hold on;
plot(rand(10,3))
a=f.Children;
L=a.Children;
D={L.YData};
E=cell2mat(D');
plot(L(1).XData,max(E),'r')
1 comentario
gwoo
el 26 de Jul. de 2018
How would you do this if they weren't on the same X domain? Notice the following doesn't give so nice an answer (I'm using minimum instead of maximum):
f=figure;hold on;
plot(sort(rand(10,1)),rand(10,1),'b',sort(rand(10,1)),rand(10,1),'g',sort(rand(10,1)),rand(10,1),'k')
a=f.Children;
L=a.Children;
D={L.YData};
E=cell2mat(D');
plot(L(1).XData,min(E),'r'
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!