I want my legend just like the pic. 2 variables in 2 columns at the same legend

1 回表示 (過去 30 日間)
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 件のコメント
Rik
Rik 2021 年 12 月 15 日
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])
Rena Berman
Rena Berman 2021 年 12 月 16 日
(Answers Dev) Restored edit

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

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 5 月 26 日
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 件のコメント
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 5 月 26 日
"Should" be as simple as:
legend([ph;ph2],[legendString;legendString2])
HTH
Leo Map
Leo Map 2021 年 5 月 26 日
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

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by