Knowing that average acceleration in a time interval ∆t = ti+1 − ti can be expressed as 𝑎𝑖 = 𝑣𝑖+1 − 𝑣𝑖 / ∆𝑡
where vi+1 − vi is the change in velocity between successive measurements,
write a code to:
3) Calculate acceleration in m/s2 using speed and time data extracted from the dataset. Hint: You may use for ... end loop to complete this task.
Driving style Economic (1) Normal (2) Aggressive (3)
Acceleration magnitude [m/s2] 0.7-2.3 2.31-3.30 3.31-8.5
Table format: as seen above
Economic (1)
0.7-2.3
Normal (2)
2.31-3.30
Aggressive (3)
3.31-8.5
close all,
clear all,
clc,
ECONOMIC = 1;
NORMAL = 2;
AGGRESSIVE = 3;
% Acceleration magnitude [m/s2] 0.7-2.3 2.31-3.30 3.31-8.5
Acc = [0.7, -2.3, 2.31, -3.30, 3.31, -8.5];
ds_mapping = [ECONOMIC,NORMAL,AGGRESSIVE];
for r=1:length(Acc)
if(abs(Acc(r))<=2.3),
fprintf('\n\tAcceleration = %5.2f m/sec^2:\t Driving Style: ECONOMIC\tCLASS: %d',Acc(r),ds_mapping(1));
end
if(abs(Acc(r))>2.3 && Acc(r) <= 3.30),
fprintf('\n\tAcceleration = %5.2f m/sec^2:\t Driving Style: NORMAL:\t\tCLASS: %d',Acc(r),ds_mapping(2));
end
if(abs(Acc(r))>3.3),
fprintf('\n\tAcceleration = %5.2f m/sec^2:\t Driving Style: AGGRESSIVE:\tCLASS: %d',Acc(r),ds_mapping(3));
end
end
fprintf('\n\n');
Comments
Leave a comment