I am getting Warning: Ignoring extra legend entries
14 views (last 30 days)
Show older comments
NoDrivel
on 1 Dec 2015
Commented: Giuseppe Degan Di Dieco
on 4 May 2021
% 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');
0 Comments
Accepted Answer
Walter Roberson
on 1 Dec 2015
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 Comments
Giuseppe Degan Di Dieco
on 4 May 2021
Dear Walter,
thanks for your tip on how the 'legend' function works.
It really helped me.
Best.
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!