How to plot the highest y values for each x value for a figure with multiple plots

3 Ansichten (letzte 30 Tage)
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

Antworten (1)

Fangjun Jiang
Fangjun Jiang am 20 Jul. 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 Kommentar
gwoo
gwoo am 26 Jul. 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'

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by