How to created plot with three lines

140 views (last 30 days)
Alex Kniffin
Alex Kniffin on 15 Feb 2015
Answered: Star Strider on 15 Feb 2015
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?

Answers (1)

Star Strider
Star Strider on 15 Feb 2015
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')

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!