How to create legend with multiple variables in a loop ?
21 ビュー (過去 30 日間)
古いコメントを表示
I want to have a comparison between two plots when a parameter 'M' have different values. I need help in writing the legend properly.
The MATLAB code that i have written is as follows.
%% Input
pro=[1 2 3; 1 2 3;]; % Each row for one value of parameter
rate=[5 10 15;15 20 25;]; % Each row for one value of parameter
bs=pro;
bs_rate=[3 8 13;13 18 23;]; % Each row for one value of parameter
%% Plot
for sz = 1:1:2
figure(1)
p=plot(pro(sz,:),rate(sz,:),'-p',...
bs(sz,:),bs_rate(sz,:),'-->');
xlabel('x-axis')
ylabel('y-axis')
p(1).LineWidth = 2; p(2).LineWidth = 2;
hold on
grid on
Legend{sz}=strcat('Proposed, M =',num2str(sz),' Benchmark M =', num2str(sz));
legend(Legend);
end
0 件のコメント
回答 (1 件)
Rik
2021 年 3 月 30 日
You should put the figure creation and the creation of the legend outside the loop.
You are merging the two texts, but you should make each a cell element.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!