How do i add legend
1 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/223871/image.png)
HI all i am just willing to add legend to the above figure where i just wana involve legend for x1 and data 1 what is the command to type that . this is an SMC controller.
0 个评论
回答(2 个)
Lizhou
2019-6-11
x = linspace(0,pi);
y1 = cos(x);
p1 = plot(x,y1);
hold on
y2 = cos(2*x);
p2 = plot(x,y2);
y3 = cos(3*x);
p3 = plot(x,y3);
hold off
legend([p1 p3],{'First','Third'})
0 个评论
Emmanuel Adesina
2021-4-24
You can simply plot all as:
plot(x,y1, x,y2, x,y3, ...)
or
line(x,y1)
line(x,y2)
line(x,y3)
...
and add all legend at once.
legend("y1","y2","y3",...)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!