MATLAB: I got an error as Warning: Ignoring extra legend entries

warning: ignoring extra legend entries

figure('name','flux vs current');
h1=plot(I1, flux1);
set(h1,'color','red','linewidth',3);
grid on;
hold all;
h2=plot(I2, flux2);
set(h2,'color','blue','linewidth',3);
grid on;
h3=plot(I3, flux3);
set(h3,'color','green','linewidth',3);
grid on;
legend([h1;h2;h3],'f1=30','f2=120','f3=400','fontsize',10);
title('flux vs current');
xlabel('current','fontsize',22);
ylabel('flux','fontsize',22);
how to overcome this. thanks in advance

Best Answer

What if you use:
legend([h1(1);h2(1);h3(1)],'f1=30','f2=120','f3=400','fontsize',10);
Just an idea; h1, h2 and h3 might contain multiple handles so selecting the 1st could solve the issue.