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

3 次查看(过去 30 天)
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

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2018-7-20
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 个评论
gwoo
gwoo 2018-7-26
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'

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by