You are on page 1of 1

close all;clc;

% % vel = [0 .45 1.79 4.02 7.15 11.18 16.09 21.90 29.05 29.05 ...
% 29.05 29.05 29.05 22.42 17.9 17.9 17.9 17.9 14.34 11.01 ...
% 8.9 6.54 2.03 0.55 0];
ACC=[];cV=[];vel=[];time=[];
ACC=Y(169:900,1)'*9.8;
tt=0.000390625;
tt2=length(ACC)-1;
time = (0:tt:tt2*tt);

figure(1)
plot(time,ACC,'-*')
grid on
title('Automobile A')
xlabel('Time (s)')
ylabel('A (m/s2)')
% xverts = [time(1:end-1); time(1:end-1); time(2:end); time(2:end)];
% yverts = [zeros(1,tt2); vel(1:end-1); vel(2:end); zeros(1,tt2)];
% p = patch(xverts,yverts,'b','LineWidth',1.5);
% % V = trapz(ACC);
cV = cumtrapz(time,ACC);
T = table(time',cV','VariableNames',{'Time','CumulativeDistance'})
figure(2)
plot(cV)
title('Cumulative V Per Second')
xlabel('Time (s)')
ylabel('V (m)')

% % vel = [0 .45 1.79 4.02 7.15 11.18 16.09 21.90 29.05 29.05 ...
% 29.05 29.05 29.05 22.42 17.9 17.9 17.9 17.9 14.34 11.01 ...
% 8.9 6.54 2.03 0.55 0];
vel=cV;
% tt=0.000390625;
% time = (0:tt:4095*tt);
figure(3)
plot(time,vel,'-*')
grid on
title('Automobile Velocity')
xlabel('Time (s)')
ylabel('Velocity (m/s)')
% xverts = [time(1:end-1); time(1:end-1); time(2:end); time(2:end)];
% yverts = [zeros(1,24); vel(1:end-1); vel(2:end); zeros(1,24)];
% p = patch(xverts,yverts,'b','LineWidth',1.5);
% % distance = trapz(vel);
cdistance = cumtrapz(time,vel);
T = table(time',cdistance','VariableNames',{'Time','CumulativeDistance'})
figure(4)
plot(cdistance)
title('Cumulative Distance Traveled Per Second')
xlabel('Time (s)')
ylabel('Distance (m)')

You might also like