Answer to Question #303961 in MatLAB for MR Z

Question #303961

Plot on the same figure the calculated acceleration and the classification variable ds mapping

against time. Use left side y-axis and a line style to plot the acceleration. Use right side

y-axis to illustrate the driving style classification. Hint: You may use plotyy to complete this

task. Add labels to all axes. Add legend to the figure.


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


Ds mapping

NORMAL = 2;

ECONOMIC = 5;

AGGRESSIVE=8;




1
Expert's answer
2022-03-02T08:20:53-0500


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 = [];
DrivingStyle = [ECONOMIC,NORMAL,AGGRESSIVE];
for r=1:length(Acc)
    if(abs(Acc(r))<=2.3), 
        ds_mapping(r) = DrivingStyle(1);
        fprintf('\n\tAcceleration = %5.2f m/sec^2:\t Driving Style: ECONOMIC\tCLASS: %d',Acc(r),ds_mapping(r));
    end
    if(abs(Acc(r))>2.3 && Acc(r) <= 3.30), 
        ds_mapping(r) = DrivingStyle(2);
        fprintf('\n\tAcceleration = %5.2f m/sec^2:\t Driving Style: NORMAL:\t\tCLASS: %d',Acc(r),ds_mapping(r));
    end
    if(abs(Acc(r))>3.3), 
        ds_mapping(r) = DrivingStyle(3);
        fprintf('\n\tAcceleration = %5.2f m/sec^2:\t Driving Style: AGGRESSIVE:\tCLASS: %d',Acc(r),ds_mapping(r));
    end
        
end
fprintf('\n\n');
scrsz = get(0,'ScreenSize');
Dim=0;
figure('Position',[scrsz(1)+Dim, scrsz(2)+Dim,scrsz(3)-20,scrsz(4)-100]);
subplot(1,2,1);
plot(Acc,'r');
grid on,
xlabel('--- Time(t) --->');
ylabel('Acceleration');
title('Plot: Acceleration','FontSize',20);


subplot(1,2,2);
plot(ds_mapping,'r');
grid on,
xlabel('--- Time(t) --->');
ylabel('ds_mapping');
title('Plot: ds-mapping','FontSize',20);




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