How to set a column vector as a legend name within multiple plots?

35 ビュー (過去 30 日間)
Andrew Lackey
Andrew Lackey 2021 年 9 月 26 日
コメント済み: Andrew Lackey 2021 年 9 月 26 日
I have a for loop that creates a figure with 5 plots. I am trying to set a legend so that each plot says "A = 0", "A = 4", "A = 8", etc.
This is the code I have so far:
figure
hold on
for i = 1:N
a1 = [0;4;8;12;16];
x = data(:,2);
v = data(:,4);
v1 = abs(v);
plot(x,v1,'color',rand(1,3))
title('Velocity Distribution')
xlabel('x/c')
ylabel('v')
legend(strcat('Alpha=',num2str(a1')))
end
However, when I do this it doesnt give me 5 legends. It only gives me one legend for one plot:
I want it to read:
(Line 1) A = 0
(Line 2) A = 4
(Line 3) A = 8

採用された回答

the cyclist
the cyclist 2021 年 9 月 26 日
Don't take the transpose:
legend(strcat('Alpha=',num2str(a1)))

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