フィルターのクリア

How could I use Legend function in a for loop with an array?

1 回表示 (過去 30 日間)
Jose Peñaloza
Jose Peñaloza 2015 年 10 月 15 日
コメント済み: Jose Peñaloza 2015 年 10 月 20 日
Hi! everyone I am trying to insert a Legend in a plot with different names but in a sequence. The problem basically is when I plot Legend, it only show me the first or the last filename I require. So I hope you can help me because I tried with different methodologies and it doesn't work. My code is the next:
for k=1:numfiles
figure(2)
legend(filename(k));
plot3(f{1,k}'/1000,((k*10^2)*10^6)+Ejey{1,k},2*q_magC{1,k},(colour(k)))
title('TRANSFORMADA DE FOURIER')
xlabel(' Frecuencia (kHz) ')
zlabel(' Magnitud ')
view(40,35)
grid on
hold all
end
Thanks in advance!
  2 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 10 月 17 日
Jose - if I do something similar and create the legend outside of the loop (or even as you have shown above within at each iteration of the loop), then all of the filenames appear as expected as legend entries. Can you show us what the filename variable is initialized to? How many curves are being drawn on your figure?
Jose Peñaloza
Jose Peñaloza 2015 年 10 月 20 日
編集済み: Jose Peñaloza 2015 年 10 月 20 日
Thank you! finally I did it, the code that let me:
for k=1:numfiles
figure(2)
leyenda=filename(1:k)
legend(leyenda)
plot3(f{1,k}'/1000,((k*10^2)*10^6)+Ejey{1,k},2*q_mag{1,k},(colour(k)))
xlim ([0 25])
title('TRANSFORMADA DE FOURIER')
xlabel(' Frecuencia (kHz) ')
zlabel(' Magnitud ')
view(40,35)
grid on
hold on
end

サインインしてコメントする。

回答 (1 件)

Stalin Samuel
Stalin Samuel 2015 年 10 月 17 日
%try like this
s = {'L1','L2','L3'};
for i = 1:length(s)
plot(rand(10,1),'color',rand(1,3));
hold on
end
legend(s)
  1 件のコメント
Jose Peñaloza
Jose Peñaloza 2015 年 10 月 20 日
Thank you for your help! Finally I did it with that code
for k=1:numfiles
figure(2)
leyenda=filename(1:k)
legend(leyenda)
plot3(f{1,k}'/1000,((k*10^2)*10^6)+Ejey{1,k},2*q_mag{1,k},(colour(k)))
xlim ([0 25])
title('TRANSFORMADA DE FOURIER')
xlabel(' Frecuencia (kHz) ')
zlabel(' Magnitud ')
view(40,35)
grid on
hold on
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by