Error message by using second legend

조회 수: 4 (최근 30일)
Marcel345614
Marcel345614 2021년 4월 22일
댓글: Marcel345614 2021년 4월 23일
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
Mario Malic
Mario Malic 2021년 4월 22일
Hi,
try this
lgd2=legend(ax2, [h1,h2],{'Experiment','Simulation'}); %this is the line which gives the error
Marcel345614
Marcel345614 2021년 4월 22일
Then I get the following error:
Error using legend (line 272)
Invalid argument. Type 'help legend' for more information.

댓글을 달려면 로그인하십시오.

채택된 답변

Marcel345614
Marcel345614 2021년 4월 23일
Using the following line instead, solved the problem.
lgd2=legend(ax2,'Experiment','Simulation','Box','off');
  댓글 수: 1
Marcel345614
Marcel345614 2021년 4월 23일
I note now that the linestyle in the legend is wrong when using this code (it shows two times -- )

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by