I want my legend just like the pic. 2 variables in 2 columns at the same legend
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Matthew Worker
am 26 Mai 2021
Bearbeitet: Rena Berman
am 16 Dez. 2021
clc;
clear;
N = [10 20 30 40 50];
M = [1 2 3 4 5];
x = linspace(0, 1, 17);
plot(x, N.*x.')
legendString = "N = " + string(N);
legendStrings = "M = " + string(M);
legend([legendString,legendStrings])
2 Kommentare
Rik
am 15 Dez. 2021
I want my legend just like the pic. 2 variables in 2 columns at the same legend
clc;
clear;
N = [10 20 30 40 50];
M = [1 2 3 4 5];
x = linspace(0, 1, 17);
plot(x, N.*x.')
legendString = "N = " + string(N);
legendStrings = "M = " + string(M);
legend([legendString,legendStrings])
Akzeptierte Antwort
Bjorn Gustavsson
am 26 Mai 2021
Solve the problem at the root:
legendString = "N = " + string(N) + ", M = " + string(M);
ph = plot(x,N.*x'); % Better controll using the plot-handle.
legend(ph,legendString)
HTH
4 Kommentare
Bjorn Gustavsson
am 26 Mai 2021
"Should" be as simple as:
legend([ph;ph2],[legendString;legendString2])
HTH
Leo Map
am 26 Mai 2021
they are not in the same order as the plot .
because I'm plotting N, M first then K, M so what you are suggesting isn't fit with the figure because it shows N, M then K, M and Again N, M and so on
Weitere Antworten (0)
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!