How to created plot with three lines

14 ビュー (過去 30 日間)
Alex Kniffin
Alex Kniffin 2015 年 2 月 15 日
回答済み: Star Strider 2015 年 2 月 15 日
I need to create a plot with three lines displayed on a single plot. I understand how to make three plots with the correct data but I need them on the same plot.
This is the format we use in my class to do so.
figure subplot(1,2,1) title () xlabel() ylabel()
This creates multiple plots. I know there is a way to make only a single plot but I cannot figure it out. Also, is there a way for me to enter a textbox that I can put an analysis of the plot in my figure?

回答 (1 件)

Star Strider
Star Strider 2015 年 2 月 15 日
I would use the hold function to put all the plots on the same axis. The other function you want is legend:
x = linspace(-5, 5);
y1=x.^2;
y2=-5*x+2 ;
y3=4*ones(size(x));
figure(1)
plot(x, y1)
hold on
plot(x, y2)
plot(x, y3)
hold off
grid
legend('y_1', 'y_2', 'y_3', 'Location', 'SW')

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by