Legend for a graph displaying multiple runs

2 views (last 30 days)
Egle on 6 Apr 2017
Commented: Egle on 7 Apr 2017
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 ];
legend ('Martinelli', 'Chisholm')
hold on
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.

Accepted Answer

Joseph Cheng
Joseph Cheng on 6 Apr 2017
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;
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 ];
legend ('Martinelli', 'Chisholm')
ltext(ind,:) = [{['point z=' num2str(ind)]},{['line z=' num2str(ind)]}]
title('all points were plotted')
legend off
legend([p(1,1); p(:,2)]',[ltext(1,1);ltext(:,2)]')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!