Changing input data sample from the same dataset

1 次查看(过去 30 天)
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.

采纳的回答

ANKUR KUMAR
ANKUR KUMAR 2021-3-1
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by