plot with 'DisplayName' in for loop

42 ビュー (過去 30 日間)
Joyce Shin
Joyce Shin 2017 年 2 月 6 日
コメント済み: Joyce Shin 2017 年 2 月 7 日
Hi, I am having trouble using plot with legend. I am trying to plot legend dynamically inside for loop. It is supposed to print 7 legend, since for loop goes from 1 to 7, but it only prints 6 legend. Do you see any problem in my code?
Here's my code.
for k=1:7
diffSum = 0;
for
% inside for loop I calculate diffSum
end
legend('-DynamicLegend');
plot(diffSum, 'color', rand(1,3), 'LineWidth', 3, 'DisplayName', sprintf('Group Thermal Comfort: %d', tc(k)));hold on;
legend('show');
drawnow;
end
hold off;

採用された回答

KSSV
KSSV 2017 年 2 月 7 日
Put this line:
legend('-DynamicLegend');
After the plot command. Like:
for k=1:7
diffSum = 0;
for
% inside for loop I calculate diffSum
end
plot(diffSum, 'color', rand(1,3), 'LineWidth', 3, 'DisplayName', sprintf('Group Thermal Comfort: %d', tc(k)));hold on;
legend('-DynamicLegend');
legend('show');
drawnow;
end
hold off;
  1 件のコメント
Joyce Shin
Joyce Shin 2017 年 2 月 7 日
Oh it worked! Thanks!

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

その他の回答 (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