Add a legend in a plot with multiples lines
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Paul Rogers
am 15 Okt. 2020
Beantwortet: Durganshu
am 16 Okt. 2020
Hi, I am having a small probllem in adding a legend, I just can't get all the names for different frequencies:
clear all;
close all;
load psi_20.mat
load time_20.mat
psi_20 = psi;
time_20 = time;
plot(time_20,psi_20)
legend('20Hz')
hold on
load psi_40.mat
load time_40.mat
psi_40 = psi;
time_40 = time;
plot(time_40,psi_40)
legend('40Hz')
hold on
load psi_60.mat
load time_60.mat
psi_60 = psi;
time_60 = time;
plot(time_60,psi_60)
legend('60Hz')
hold on
load psi_80.mat
load time_80.mat
psi_80 = psi;
time_80 = time;
plot(time_80,psi_80)
legend('80Hz')
hold on
load psi_100.mat
load time_100.mat
psi_100 = psi;
time_100 = time;
plot(time_100,psi_100)
legend('100Hz')
hold on
I have matlab 2014b
0 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 16 Okt. 2020
hi
simplest code below - more sophisticated is always possible...
% simple code
load psi_20.mat
load time_20.mat
psi_20 = psi;
time_20 = time;
load psi_40.mat
load time_40.mat
psi_40 = psi;
time_40 = time;
load psi_60.mat
load time_60.mat
psi_60 = psi;
time_60 = time;
load psi_80.mat
load time_80.mat
psi_80 = psi;
time_80 = time;
load psi_100.mat
load time_100.mat
psi_100 = psi;
time_100 = time;
plot(time_20,psi_20,time_40,psi_40,time_60,psi_60,time_80,psi_80,time_100,psi_100);
legend('20Hz','40Hz','60Hz','80Hz','100Hz')
0 Kommentare
Weitere Antworten (1)
Durganshu
am 16 Okt. 2020
Don't use legend multiple times.
You can use this command after plotting all the plots.
legend('20Hz', '40Hz', '60Hz', '80Hz', '100Hz')
Hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!