I am getting Warning: Ignoring extra legend entries

11 vues (au cours des 30 derniers jours)
NoDrivel
NoDrivel le 1 Déc 2015
% 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');

Réponse acceptée

Walter Roberson
Walter Roberson le 1 Déc 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 commentaires
NoDrivel
NoDrivel le 1 Déc 2015
Cheers. Nice day.
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco le 4 Mai 2021
Dear Walter,
thanks for your tip on how the 'legend' function works.
It really helped me.
Best.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by