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

조회 수: 15 (최근 30일)
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 CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by