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

3 ビュー (過去 30 日間)
Edema Rhu
Edema Rhu 2018 年 7 月 20 日
コメント済み: gwoo 2018 年 7 月 26 日
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 Center および File ExchangeCreating, 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