Answer to Question #303956 in MatLAB for MR Z

Question #303956

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. If the acceleration value is outside the defined ranges assign 0 as its classification.


Table 1 (4 by 2)


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

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


Economic (1)

0.7-2.3


Normal (2)

2.31-3.30


Aggressive (3)

3.31-8.5 


1
Expert's answer
2022-03-02T01:16:01-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 ]


    Economic (1)    0.7-2.3
    Normal(2)       2.31-3.30
    Aggressive(3)   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
%}
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');

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