Answer to Question #301159 in MatLAB for Mr Z

Question #301159

Table 1: Driving styles associated with acceleration values


Driving style Economic (1) Normal (2) Aggressive (3)

Acceleration magnitude [m/s2 ] 0.7-2.3 2.31-3.30 3.31-8.5 



Create variable ds mapping to store corresponding classification values of 1,2 or 3, which represent different driving style as shown in Table 1. You need to evaluate only the magnitude the of the acceleration/deceleration.


1
Expert's answer
2022-02-23T00:10:18-0500


close all,
clear all,
clc,


%{
    Table 1: Driving styles associated with acceleration values
    Driving style Economic (1) Normal (2) Aggressive (3)
    Acceleration magnitude [m/s2 ] 0.7-2.3 2.31-3.30 3.31-8.5 
    Create variable ds mapping to store corresponding classification values of 1,2 or 3, 
    which represent different driving style as shown in Table 1. 
    You need to evaluate only the magnitude the of the acceleration/deceleration
%}
A = [0.7, -2.3, 2.31, -3.30, 3.31, -8.5]


NORMAL = 2;
ECONOMIC = 5;
AGGRESSIVE=8;


for r=1:length(A)
    if(abs(A(r))<=NORMAL), 
        fprintf('\n\nDriving Style: Normal, Acceleration = %.2f m/s2',A(r));
    end
    if(abs(A(r))>NORMAL && abs(A(r))<=ECONOMIC), 
        fprintf('\n\nDriving Style: Economic, Acceleration = %.2f m/s2',A(r));
    end
    if(abs(A(r))>ECONOMIC), 
        fprintf('\n\nDriving Style: Agressive, Acceleration = %.2f m/s2',A(r));
    end
end
fprintf('\n\n');


Matlab utput:

A =


  0.7000  -2.3000  2.3100  -3.3000  3.3100  -8.5000




Driving Style: Normal, Acceleration = 0.70 m/s2


Driving Style: Economic, Acceleration = -2.30 m/s2


Driving Style: Economic, Acceleration = 2.31 m/s2


Driving Style: Economic, Acceleration = -3.30 m/s2


Driving Style: Economic, Acceleration = 3.31 m/s2


Driving Style: Agressive, Acceleration = -8.50 m/s2


>> 


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS