Legend for a graph displaying multiple runs

3 ビュー (過去 30 日間)
Egle
Egle 2017 年 4 月 6 日
コメント済み: Egle 2017 年 4 月 7 日
Hello,
I have a working code for calculation of agch. I now want to see how different values of input Z affect the final results. I managed to plot runs with different Z values on one graph using hold on.
function [angle, alpha, al, agch, Al, Ag] = getanglech
[D, A, R] = geom();
[n, m] = setglblch();
X = setX();
[Xlm, aglm] = martineli();
for Z = 5:20
angle = arrayfun( @(X) fzero( @(angle) equationsch (angle, X, D, A, R, m, n, Z) , [1E-4, pi-1E-4]), X );
Ag = (R^2)*(pi-angle+0.5*sin(2*angle)) ;
Al = (R^2)*(angle-0.5*sin(2*angle)) ;
Slw = 2*R*angle ;
alpha = (4*Al)./(Slw*D) ;
al = Al/A ;
agch = Ag/A ;
p=loglog(Xlm, aglm, 'o', X, agch);
p(1).MarkerEdgeColor = [0 0 0 ];
xlabel('X')
ylabel('ag')
legend ('Martinelli', 'Chisholm')
legend('Location','best')
hold on
end
end
However, the legend is messy (picture attached). It should be clear in the plot which value of Z each line represents. Also, the Martinelli data should only have on entry in the legend and not every second. Can this be done? Any help appreciated.
%

採用された回答

Joseph Cheng
Joseph Cheng 2017 年 4 月 6 日
you can look into specifying which points/lines are plotted in the legend() help documentation.
I made a quick example that you can see what is going on first of all then how to define which ones get into the legend
x =0:.1:10;
figure(1),clf
hold on
for ind = 1:10
p(ind,:) = loglog(ind,ind.^ind+ind,'o',x,x.^ind+ind);
p(ind,1).MarkerEdgeColor = [0 0 0 ];
xlabel('X')
ylabel('ag')
legend ('Martinelli', 'Chisholm')
legend('Location','best')
ltext(ind,:) = [{['point z=' num2str(ind)]},{['line z=' num2str(ind)]}]
end
title('all points were plotted')
pause(5)
legend off
legend([p(1,1); p(:,2)]',[ltext(1,1);ltext(:,2)]')
  1 件のコメント
Egle
Egle 2017 年 4 月 7 日
Hi Joseph this helped, thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by