Determine driving styles of a driver

조회 수: 1 (최근 30일)
Ben Morgan
Ben Morgan 2022년 4월 26일
답변: Aman 2024년 2월 6일
ZERO = 0
ECONOMIC = 1
NORMAL = 2
AGGRESSIVE = 3
ds_mapping= [ZERO,ECONOMIC,NORMAL,AGGRESSIVE]
for r=0:length(Acceleration)
if(abs(Acceleration(r))<=0.7),
fprintf('\n\tAcceleration = %5.2f m/sec^2:\t Driving Style: ZERO\tCLASS: %d',Acceleration(r),ds_mapping(0))
end
for r=1:length(Acceleration)
if(abs(Acceleration(r))>=0.7),
fprintf('\n\tAcceleration = %5.2f m/sec^2:\t Driving Style: ECONOMIC\tCLASS: %d',Acceleration(r),ds_mapping(1))
end
if(abs(Acceleration(r))>2.79 && Acceleration (r) <= 3.30),
fprintf('\n\tAcceleration = %5.2f m/sec^2:\t Driving Style: NORMAL:\t\tCLASS: %d',Acceleration(r),ds_mapping(2))
end
if(abs(Acceleration (r))>3.63),
fprintf('\n\tAcceleration = %5.2f m/sec^2:\t Driving Style: AGGRESSIVE:\tCLASS: %d', Acceleration(r),ds_mapping(3))
end
end
fprintf('\n\n')
  댓글 수: 8
Ben Morgan
Ben Morgan 2022년 4월 27일
Hi, so driving style 0 would be anything below 0.7. The question only states 3 driving styles, yet the graph we need to plot has 4 different values the driving style can be. 0, 1, 2 and 3.
Ben Morgan
Ben Morgan 2022년 4월 27일
-I currently have :
for r=1:length(Acceleration)
if (abs(Acceleration(r)) < 0.7)
disp ('0')
end
if (abs(Acceleration(r)) >= 0.7 && abs(Acceleration(r) < 2.79))
disp ('1')
end
if (abs(Acceleration(r)) >= 2.79 && abs(Acceleration(r) < 3.64))
disp ('2')
end
if (abs(Acceleration(r)) >= 3.64)
disp ('3')
end
end
-And this seems to work. All I need to do now is turn this into a variable so I am able to plot it against time on a graph.

댓글을 달려면 로그인하십시오.

답변 (1개)

Aman
Aman 2024년 2월 6일
Hi Ben,
As per my understanding, you want to classify the driving system based on the acceleration and the mapping table shared and are facing issues while doing so.
You can achieve the same using the code below, where I'm populating the "ds_mapping" based on the mapping table and then creating a line plot with two different variables on both y-axes of the plot. Please not, as the actual acceleration array was not present, so I have created a random acceleration array.
a = -6.5;
b = 6.5;
timeInterval = 1800;
acceleration = a + (b-a) * rand(1,timeInterval);
ds_mapping = [];
for i=1:timeInterval
if(abs(acceleration(i))<0.7)
ds_mapping = [ds_mapping,0];
elseif(abs(acceleration(i))>=0.7 && abs(acceleration(i))<2.79)
ds_mapping = [ds_mapping,1];
elseif(abs(acceleration(i))>=2.79 && abs(acceleration(i))<3.64)
ds_mapping = [ds_mapping,2];
elseif(abs(acceleration(i))>=3.64)
ds_mapping = [ds_mapping,3];
end
end
figure;
hold on;
title("Acceleration and Driving Style classification");
xlabel("Time(s)");
yyaxis left;
plot(1:timeInterval,acceleration,"Color","blue");
ylabel("Acceleration(ms^2)");
ylim([-6.5 6.5]);
yyaxis right;
plot(1:timeInterval,ds_mapping,"Color","cyan");
ylabel("Driving Style");
ylim([0 3]);
hold off;
I hope it helps!

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by