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

조회 수: 3 (최근 30일)
Matthew Worker
Matthew Worker 2021년 2월 10일
답변: madhan ravi 2021년 2월 10일
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?

답변 (1개)

madhan ravi
madhan ravi 2021년 2월 10일
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)')

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by