Borrar filtros
Borrar filtros

Error message by using second legend

2 visualizaciones (últimos 30 días)
Marcel345614
Marcel345614 el 22 de Abr. de 2021
Comentada: Marcel345614 el 23 de Abr. de 2021
I'm using the approach presented in the following link:
I get the following error message for the second legend:
Operands to the || and && operators must be convertible to logical scalar values.
Error in legend (line 173)
graphicsInput % legend(children,strings,...)
My code for the second legend:
ax2=copyobj(ax1,gcf);
hold on
delete(get(ax2,'Children'))
xhelp=0.2:0.1:1.5;
yhelp=ones(length(xhelp));
h1=plot(xhelp,yhelp,'k','Parent', ax2,'Visible', 'off');
h2=plot(xhelp,yhelp,'k--','Parent', ax2,'Visible', 'off');
set(ax2, 'Color', 'none', 'Box', 'Off', 'Visible', 'off')
hold off
lgd2=legend([h1,h2],{'Experiment','Simulation'}); %this is the line which gives the error
title('lgd2','Linestyles')
set(lgd2,'Color','none')
  2 comentarios
Mario Malic
Mario Malic el 22 de Abr. de 2021
Hi,
try this
lgd2=legend(ax2, [h1,h2],{'Experiment','Simulation'}); %this is the line which gives the error
Marcel345614
Marcel345614 el 22 de Abr. de 2021
Then I get the following error:
Error using legend (line 272)
Invalid argument. Type 'help legend' for more information.

Iniciar sesión para comentar.

Respuesta aceptada

Marcel345614
Marcel345614 el 23 de Abr. de 2021
Using the following line instead, solved the problem.
lgd2=legend(ax2,'Experiment','Simulation','Box','off');
  1 comentario
Marcel345614
Marcel345614 el 23 de Abr. de 2021
I note now that the linestyle in the legend is wrong when using this code (it shows two times -- )

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by