What type of code should i use and how to use it?
1 view (last 30 days)
Show older comments
Saiyed Sabahat
on 17 Feb 2019
Commented: Saiyed Sabahat
on 19 Feb 2019
Hi,
I am trying to plot a graph of a vehicles type of acceleration ie. Eco, Nor, Agg, Any; from a set of data. I have tried everything that i have been tought but cant figure out what how to complete it. The graph needs to show all values in range 0.7 - 2.8 as 1, 2.81 - 3.64 as 2, 3.65 - 6.5 as 3 and every other value 0. I also needs to use variable ds_mapping to store corresponding classification values of 1,2 or 3.
my_data=readtable('Log_U0006387_160311_740d0.csv');
speed2=my_data.Speed*0.44704; %Speed is extracted in m/s from the dataset
acceleration= diff(speed2)./diff(time); %Finds acceleration as a derivative of speed with respect to time
Acceleration= resample(acceleration, 621,620); %as acceleration had only 620 cells and time has 621 cells
ds_mapping=0;
for Acceleration2=sqrt(Acceleration.^2);
if Acceleration2>=0.7 & Acceleration2<=2.8;
ds_mapping = ds_mapping+1;
elseif Acceleration2>=2.81 & Acceleration2<=3.64;
ds_mapping = ds_mapping+2;
elseif Acceleration2>=3.65 & Acceleration2<=6.5;
ds_mapping = ds_mapping+3;
elseif Acceleration2<=2.80 & Acceleration2>=6.6;
ds_mapping = ds_mapping+0;
end
end
%Plot graph
figure (3)
xlabel('Time (s)'); ylabel('Acceleration (m/s2)');
plot(time, Acceleration, 'm', time, ds_mapping)
0 Comments
Accepted Answer
Geoff Hayes
on 17 Feb 2019
Saiyed - if Acceleration is the array with all of the data that you want to classify, then you could loop over each element in this array and determine the correct classification for each. For example,
ds_mapping = zeros(size(Acceleration)); % default to zeros
for k = 1:length(Acceleration)
accelValue = Acceleration(k);
if accelValue >= 0.7 && accelValue <= 2.8
ds_mapping(k) = 1;
elseif accelValue >= 2.81 && accelValue <= 3.64
ds_mapping(k) = 2;
elseif accelValue >= 3.65 && accelValue <= 6.5
ds_mapping(k) = 3;
end
end
And then plot the results.
More Answers (0)
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!