How do I indicate phase changes on my velocity versus time plot on MATLAB?

1 view (last 30 days)
I have a graph that plots velocity versus time and I have to indicate where/which data point on the plot accelerates, stays constant, and decelerates. This is what I have for graphing my plot:
>> t = [1.85 2.87 3.78 4.65 5.5 6.32 7.14 7.96 8.79 9.69]
>> d = [10 20 30 40 50 60 70 80 90 100]
>> v = diff(d)./diff(t)
>> plot(v)
>> title('Time versus Velocity for Usain Bolt')
>> xlabel('Time(s)')
>> ylabel('Velocity(m/s)')
>> figure(1)
Can someone please help me?

Answers (1)

madhan ravi
madhan ravi on 10 Feb 2021
t = [1.85 2.87 3.78 4.65 5.5 6.32 7.14 7.96 8.79 9.69];
d = 10: 10 : 100;
v = gradient(d) ./ gradient(t);
figure(1)
dvdt = gradient(v) ./ gradient(t);
%deceleration:
t1 = t(dvdt < 0);
v1 = v(dvdt < 0);
%acceleration:
t2 = t(dvdt > 0);
v2 = v(dvdt > 0);
% P.S :constant part is quite tricky ;)
plot(t, v, '-*k', t1, v1, '-r*', t2, v2, '-g*')
legend({'Constant acceleration', 'Deceleration', 'Acceleration'}, 'location', 'best')
title('Time versus Velocity for Usain Bolt')
xlabel('Time(s)')
ylabel('Velocity(m/s)')

Tags

Community Treasure Hunt

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

Start Hunting!