Changing input data sample from the same dataset

1 view (last 30 days)
I have script mapping the driving of vehicles. The data for the vehicles are listed like this:
Vehicle nr.
173 Data
173 Data
173 Data
174 Data
174 Data
174 Data
and so on. I have made a script for vehicle 173. The first vehicle, Vehicle 173 has 224 GPS-measurements (First value at row 1 and last at row 224 )
But now I want to run it again for another vehicle. Vehicle 174s first measurement is at row 225 and the last one is at row 360. However, it is not feasible for my script. So somehow I need to detach each vehicle from the list, so every vehicle constitute its own list of 1:XXX. That is, for vehicle 174, this becomes From row 1 to 136 instead.

Accepted Answer

ANKUR KUMAR
ANKUR KUMAR on 1 Mar 2021
SInce you have not attached sample data, that is why I am generating some random dataset like yours.
dataset=randi(5,23,6); dataset(:,1)=dataset(:,1)+170;
Code will work in both cases whether first column is sorted or not.
unique_vehicle_id=unique(dataset(:,1));
for i = 1:length(unique_vehicle_id)
output=dataset(dataset(:,1)==unique_vehicle_id(i),:)
end
If you wish to save output in cell array, you can use the below code:
for i = 1:length(unique_vehicle_id)
output_cellarray{i}=dataset(dataset(:,1)==unique_vehicle_id(i),:)
end
Hope this helps.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!