I am getting Warning: Ignoring extra legend entries

% T represents Temperature in Kelvin,K
% mu represnt Viscosity
%downloading the ascii data file
Data = importdata('viscosity_data.dat');
T= Data(1,:);
mu= Data(2,:);
% to return the no.of elements n1 & n2 in arrays of T & mu
n1=numel(T);
n2=numel(mu);
i=0; % dependent variable, changing w/change in temp.
if n1==n2
K=input('Enter Temperature,K at which to estimate Viscosity: ');
if K>=T(1) && K<=T(n1)
% for loop
for m=1:n1
if T(m)==K;
i=mu(m);
end %end if 6
if(i==0)
if (K<=T(m) && K>=T(m-1))
% applying the variable into linear interpolation equation
i=(mu(m)-mu(m-1))/(T(m)-T(m-1))*(K-T(m)+mu(m));
end %end if 5
end %end if 4
end %end for loop 3
else
fprintf('Temperature not within Range, Try again.');
end %end if 2
else
fprintf('Invalid Data. Rerun program');
end %end if 1
plot(T,mu,'-o');
grid on
legend('T','mu');
xlabel('Temperature, T/K');
ylabel('Viscosity (*10^-5 kg/ms');
title('Viscosity versus Temperature');

 채택된 답변

Walter Roberson
Walter Roberson 2015년 12월 1일

1 개 추천

You can have at most one legend entry for each plot object. You are only plotting one line, so you can have only one legend entry.
You should not be trying to legend() each variable: that is what xlabel() and ylabel() are for.

댓글 수: 3

If you want to point out a particular location on the plot, you should consider using annotation() or text(). legend() is mostly for the case that you have multiple graphics objects in a plot (such as multiple lines) and you want to give at key about which line has which meaning.
Cheers. Nice day.
Dear Walter,
thanks for your tip on how the 'legend' function works.
It really helped me.
Best.

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

추가 답변 (0개)

카테고리

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by