# How to deal with legend for multiple curves in one figure?

24 visualizzazioni (ultimi 30 giorni)
Haitham AL Satai il 20 Lug 2022
Commentato: Voss il 20 Lug 2022
I have a multiple curevs in one figure and I wanna add a legend to each curve.
So, instead of data1, data2, data3, data4, and data5, I want to replace them with
phi = 0 & psi = 0
phi = psi
phi = [0,5,10,15,20,25,30] & psi = 0
phi = 0 & psi = [0,5,10,15,20,25,30]
phi = [0,5,10,15,20,25,30] & psi = [0,5,10,15,20,25,30]
I tried many times, but I could not reach to solution. May I get an assistance please?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Voss il 20 Lug 2022
Modificato: Voss il 20 Lug 2022
One way is to set the DisplayName of each line when you plot it:
names = {
'phi = 0 & psi = 0'
'phi = psi'
'phi = [0,5,10,15,20,25,30] & psi = 0'
'phi = 0 & psi = [0,5,10,15,20,25,30]'
'phi = [0,5,10,15,20,25,30] & psi = [0,5,10,15,20,25,30]'
};
hold on % do "hold on" before you plot
for ii = 1:5
plot(rand(1,10),rand(1,10),'DisplayName',names{ii}); % (plotting random data because I don't have your data)
end
xlabel('X (m)');
legend();
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Haitham AL Satai il 20 Lug 2022
Voss il 20 Lug 2022
Thank you!

Accedi per commentare.

### Categorie

Scopri di più su Legend in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by