필터 지우기
필터 지우기

How to start a plot on the same axis at a different value?

조회 수: 2 (최근 30일)
Seba.V
Seba.V 2019년 10월 28일
답변: David Hill 2019년 10월 28일
Hi guys,
I am trying to plot two different linear equations functions and the sum of the two together. However, I would like to have one of the lines to start from zero when x=2 instead of when x=0. The resultant linear plot of the sum of the two functions that I am seeking should be equal to the function (y) until function (y1) starts at 2 and it would then decrease and become negative (since y1 decreases at a higher rate).
I hope it is clear enough my expalnation of what I am trying to do.
This is the code I have used.
x=0:1:24;
y=2*x;
y1=-4*(x-2);
r=y+y1;
plot(x,y,x,y1,x,r)
grid on
legend('y','y1','r')
Thank you in advance

답변 (1개)

David Hill
David Hill 2019년 10월 28일
x=0:1:24;
y=2*x;
y1=-4*(x-2);
y1(1:2)=0;%y1=0 when x<2 (if you change the x vector you will need to change this
r=y+y1;
plot(x,y,x,y1,x,r)
grid on
legend('y','y1','r')

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by