trouble plotting driving style from acceleration

clc;
clear all;
Mydata2=xlsread('Log_U0006387_160311_740d0.csv');
t=Mydata2(:,1);
v=Mydata2(:,3)*1.60934*1000/3600;
a = diff(v)./diff(t)
diff(v);
if a <0
a=inv(a); %To receive positive values for acceleration
end
if a < 0.7
ds_mapping = 0
end
for i = 1:length(a)
if a(i) >= 0.7
ds_mapping = 1;
elseif a <= 2.81
ds_mapping = 2;
elseif a <= 3.65
ds_mapping = 3;
end
end
yyaxis left
plot(t(2:end),a , 'r')
xlabel('time')
ylabel('Acceleration');
hold on
yyaxis right
plot(t(2:end),ds_mapping , 'b')
ylabel('DS');
hold off
grid on
this is the code I currently have i'm trying to plot the driving style between those ranges however, my answer keeps returning to zero

댓글 수: 5

1 - You need to store ds_mapping as a vector.
2 - Why are you comparing a vector against a scalar?
if a <0
%
if a < 0.7
3 - Why are you taking inverse of a vector?
a=inv(a); %To receive positive values for acceleration
Did you want to get the absolute value of real numbers? Then simpy use abs
so essentially I have calculated values for acceleration, there should be an image of what the question looks like. What I now need to do is store those values and then plot them on a graph that looks like the one shown in the images. I did not know i was comparing a vector to a scalar. I am taking the inverse of a as i want the absolute values when I used abs(a) it wasn't working for some reason. How do i store ds_mapping as a vector?
Dyuman Joshi
Dyuman Joshi 2023년 8월 7일
편집: Dyuman Joshi 2023년 8월 7일
"How do i store ds_mapping as a vector?"
Check out the documentation of for loop, as the hint suggests.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2023년 8월 4일

편집:

2023년 8월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by