Plot not as expected

1 view (last 30 days)
Mu Li
Mu Li on 28 Mar 2015
Edited: James Tursa on 28 Mar 2015
Could someone help me with this t=1:1:200
v1=1+3*t
v2=1-0.2*t
vs=v1
vs(v1>60)=v2(v1>60)
plot(t,vs)
I was trying to plot the velocity of an object.It accelerate at 3 m/s2 until 60, and then slows down at 0.2.
The plot consists of dispersed parts from the two functions, instead of a zigzag fluctuation around 60 which is what I am trying to achieve. I understand why the plot is like this, but failed to come up with a solution.
  1 Comment
James Tursa
James Tursa on 28 Mar 2015
Edited: James Tursa on 28 Mar 2015
Is the "greater-than-60" criteria assumed to only be checked on the 1 sec boundaries? The resulting velocity is going to depend on exactly when you make this check. You may need to put this in a for loop and step-by-step apply the +3.0 or the -0.2 depending on the current value of velocity.

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!