Legend in plot with a loop
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have some data which plots 48 different figures for 48 different points. I want to have some kind of loop which can be used in the Legend command for the plotting so that I don't have to write the Legend for the figures. I have the 48 points in a variable =a in the workspace.
for j=1:48
figure;
normB48points=(normB(:,j));
plot(t',normB48points);
xlabel('time in seconds (t)');
ylabel('flux densities in Tesla (T)');
legend('flux densities at point');
end
0 个评论
采纳的回答
Rakhi Agarwal
2019-2-22
Try this:
for j=1:48
figure;
normB48points=(normB(:,j));
plot(t',normB48points);
xlabel('time in seconds (t)');
ylabel('flux densities in Tesla (T)');
name = ['Flux densities at ', num2str(j)];
legend(name);
end
2 个评论
Rakhi Agarwal
2019-2-22
Then just modify the above code as follows:
Instead of:
name = ['Flux densities at ', num2str(j)];
Use:
name = ['Flux densities at ', num2str(a(1,j),',', num2str(a(2,j)];
where a is your coordinate vector.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!