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

14 views (last 30 days)
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

Accepted Answer

the cyclist
the cyclist on 26 Sep 2021
Don't take the transpose:
legend(strcat('Alpha=',num2str(a1)))

More Answers (0)

Community Treasure Hunt

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

Start Hunting!