MATLAB Answers

Create complex legend with two string including variables values.

7 views (last 30 days)
Davide Bassignana
Davide Bassignana on 19 Nov 2017
I'm trying to add a legend to a plot where multiple variable are plotted in two y axes. I want to highlight two values on this plot (concerning only one axis) and add a legend about only this points.
here is the code:
p5=plot(U(kk1),real(sol(kk1,:)),'d','MarkerSize',15,'Color','b');
p6=plot(U(kk2),real(sol(kk2,:)),'o','MarkerSize',15,'Color','b');
str_lgd1 =['Real eigenvalue for U = ',...
num2str(U_stop(1)), ' m/s' char(10) 'Re(p) = ', ...
num2str(abs(real(sol(kk1,1))))];
str_lgd2 = ['Real eigenvalue for U = ',...
num2str(U_stop(2)), ' m/s' char(10) 'Re(p) = ', ...
num2str(abs(real(sol(kk2,1))))];
lgd=legend([p5 p6],str_lgd1,str_lgd2);
p5 and p6 are the objects I want to add the legend. str_lgd1 and str_lgd2 are the string I want to be displayed. The error is:
Operands to the || and && operators must be convertible to logical scalar values.
Error in legend (line 189)
all(isgraphics(args{1})) % legend(children,strings,...)
Error in Es4 (line 244)
lgd=legend([p5 p6],{str_lgd1,str_lgd2});

Answers (0)

Community Treasure Hunt

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

Start Hunting!