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 Kommentare

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 am 7 Aug. 2023
Bearbeitet: Dyuman Joshi am 7 Aug. 2023
"How do i store ds_mapping as a vector?"
Check out the documentation of for loop, as the hint suggests.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 4 Aug. 2023

Bearbeitet:

am 7 Aug. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by