# Legend Problem

3 views (last 30 days)
Okan on 26 Jun 2012
Hi,
I have a code calculating the FFts of different data texts and when Fourier Amplitudes are plotted after computation, Matlab gives a warning "Ignoring extra legend entries. > In legend at 278" and doesn' t plot A551 Matrix shown below. In addition to this, Although I assign red and green color to A331, A441 Matrices, respectively, They are showed as green and yellow in Figure. The related part of my code is below;
elseif (nofnn(1)==2) & (nofnn(2)==3)& (nofnn(3)==4)
for l=1:nofn
'ACC_1_2D_2','ACC_1_3D_1',...
'ACC_1_3D_2','ACC_1_3D_3',...
'ACC_2_1D_1','ACC_2_2D_1',...
'ACC_2_2D_2','ACC_2_3D_1',...
'ACC_2_3D_2','ACC_2_3D_3',...
'ACC_3_2D_1','ACC_3_2D_2',...
'ACC_4_2D_1','ACC_4_2D_2',...
'ACC_5_2D_1','ACC_5_2D_2',...
'ACC_6_2D_1','ACC_6_2D_2',...
'CLU_10_A1','CLU_10_A2',...
'CLU_11_A1','CLU_11_A2',...
'CLU_1_A1','CLU_1_A2',...
'CLU_2_A1','CLU_2_A2',...
'CLU_4_A1','CLU_4_A2',...
'CLU_4_A3','CLU_5_A1',...
'CLU_5_A2','CLU_6_A1',...
'CLU_6_A2','CLU_7_A1',...
'CLU_7_A2','CLU_9_A1',...
'CLU_9_A2','CLU_9_A3');
if (nn(l)==2) | (nn(l)==3) | (nn(l)==8) | (nn(l)==9) | (nn(l)==13) | (nn(l)==14) | (nn(l)==15) | (nn(l)==16) | (nn(l)==17) | (nn(l)==18) | (nn(l)==19) | (nn(l)==20)
%a3(:,l)=detrend(a3(:,l),'constant');
%a3(:,l)=detrend(a3(:,l));
%a4(:,l)=detrend(a4(:,l),'constant');
%a4(:,l)=detrend(a4(:,l));
%a5(:,l)=detrend(a5(:,l),'constant');
%a5(:,l)=detrend(a5(:,l));
A3(:,l)=fft(a3(:,l),2^nextpow2(length(a3(:,l))));
A31(:,l)=abs(A3(:,l))*0.01;
%A31(1,l)=A31(1,l);
A4(:,l)=fft(a4(:,l),2^nextpow2(length(a3(:,l))));
A41(:,l)=abs(A4(:,l))*0.01;
%A41(1,l)=A41(1,l);
A5(:,l)=fft(a5(:,l),2^nextpow2(length(a3(:,l))));
A51(:,l)=abs(A5(:,l))*0.01;
%A51(1,l)=A51(1,l);
Fs=100;
f=Fs*(1:2^nextpow2(length(a3(:,l)))/2)/(2^nextpow2(length(a3(:,l))));
figure (l)
loglog(f,A31((1:2^nextpow2(length(a3(:,l)))/2),l),'r');
title(names1{nn(l)});
xlabel('Frequency (Hz)');
ylabel('Fourier Amplitude');
loglog(f,A41((1:2^nextpow2(length(a3(:,l)))/2),l),'g');
hold on
title(names1{nn(l)});
xlabel('Frequency (Hz)');
ylabel('Fourier Amplitude');
loglog(f,A51((1:2^nextpow2(length(a3(:,l)))/2),l),'y');
title(names1{nn(l)});
xlabel('Frequency (Hz)');
ylabel('Fourier Amplitude');
legend('Ornek3','Ornek4','Ornek5');
else
A33(:,l)=fft(a31(:,l),2^nextpow2(length(a31(:,l))));
A331(:,l)=abs(A33(:,l))*0.02;
%A331(1,l)=A331(1,l);
A44(:,l)=fft(a41(:,l),2^nextpow2(length(a31(:,l))));
A441(:,l)=abs(A44(:,l))*0.02;
%A441(1,l)=A441(1,l);
A55(:,l)=fft(a51(:,l),2^nextpow2(length(a31(:,l))));
A551(:,l)=abs(A55(:,l))*0.02;
%A551(1,l)=A551(1,l);
Fs=50;
f=Fs*(1:2^nextpow2(length(a31(:,l)))/2)/(2^nextpow2(length(a31(:,l))));
figure (l)
loglog(f,A331((1:2^nextpow2(length(a31(:,l)))/2),l),'r');
title(names1{nn(l)});
xlabel('Frequency (Hz)');
ylabel('Fourier Amplitude');
hold on
loglog(f,A441((1:2^nextpow2(length(a31(:,l)))/2),l),'g');
title(names1{nn(l)});
xlabel('Frequency (Hz)');
ylabel('Fourier Amplitude');
loglog(f,A551((1:2^nextpow2(length(a31(:,l)))/2),l),'y');
title(names1{nn(l)});
xlabel('Frequency (Hz)');
ylabel('Fourier Amplitude');
legend('Ornek3','Ornek4','Ornek5');
end
end
Why does Matlab ignore the last entry of legend?

Dr. Seis on 3 Jul 2012
Matlab is only doing what you tell it to. One of the places where you define your figure, you have your "hold on" just after your second "loglog" plot:
figure (l)
loglog(f,A31((1:2^nextpow2(length(a3(:,l)))/2),l),'r');
title(names1{nn(l)});
xlabel('Frequency (Hz)');
ylabel('Fourier Amplitude');
loglog(f,A41((1:2^nextpow2(length(a3(:,l)))/2),l),'g');
hold on
title(names1{nn(l)});
xlabel('Frequency (Hz)');
ylabel('Fourier Amplitude');
loglog(f,A51((1:2^nextpow2(length(a3(:,l)))/2),l),'y');
title(names1{nn(l)});
xlabel('Frequency (Hz)');
ylabel('Fourier Amplitude');
legend('Ornek3','Ornek4','Ornek5');
This is different from the way you do it later in the code you posted, where you have the "hold on" after the first "loglog" plot.
Incidentally, if you are plotting on the same figure axis, then you do not need to define your title, xlabel and ylabel for each plot. If you were plotting each on a different "subplot", then you would need to do this.