I have to plot a group of lines (10 in total, divided in 2 groups of 5 each), but I want the legend only for the groups.
It seems easy, I followed the accepted answer here: legend for group of lines
and it makes sense to me, but when I execute it, I get an error:
Operands to the || and && operators must be convertible to logical scalar values. Error in legend (line 198) elseif narg > 0 && ~ischar(varargin{1}) && ...
this is the code, I don't know if it's because of the "eval" command but I get the plot...
figure(3)
h1=plot(res(:,17),(res(:,16)./10^6),prop,...
res(:,64),(res(:,92)./10^6),prop,...
res(:,65),(res(:,93)./10^6),prop,...
res(:,66),(res(:,94)./10^6),prop,...
res(:,67),(res(:,95)./10^6),prop,...
'linewidth',2);
hold on
for ii=1:ngrains
eval(['h2(',num2str(ii),',1)=plot(',names{ii},'.VMSTRAIN,',names{ii},'.VMSTRESS,prop2,''linewidth'',2)']);
hold on
Here is the code I used to add the legend:
legend([h1 h2],{'label1', 'label2'});