フィルターのクリア

Showing Legend of Plot of Array?

2 ビュー (過去 30 日間)
Brandon Luciano
Brandon Luciano 2018 年 2 月 12 日
回答済み: Star Strider 2018 年 2 月 12 日
I am trying to plot two arrays and display the legend but having trouble displaying each of the three elements in the figure.
The figure is correct, however, how can I create a legend for each of the 3 lines that are outputted in the form of Line_1 = [-8,-9] Line_2 = [-.8,-.9] Line_3 = [-9,.9]
t = 0:0.01:10;
A = [-8; -.8; .8];
B = [-9;-.9; .9];
m1 = .6;
m2 = -.8;
Y1 = (A*exp(-m1*t)) + (B*exp(-m2*t));
figure(1);
plot(t,Y1);
%legend('');

採用された回答

Star Strider
Star Strider 2018 年 2 月 12 日
Try this:
figure(1);
plot(t,Y1);
lgnd = regexp(sprintf('Line %d = [%.1f %.1f]\n', [(1:3)' A B]'), '\n', 'split');
legend(lgnd(1:3), 'Location','SW');

その他の回答 (0 件)

カテゴリ

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