How to created plot with three lines

조회 수: 12 (최근 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 CenterFile Exchange에서 2-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