Separating and splitting table by numeric values and writing to multiple files
Show older comments
I have a single CSV with data uploaded from multiple IOT sensors (all within the same file), each device's row distinguished by a unique numeric ID. I convert this into a MATLAB table using the
readtable()
method. I can then organize the file by grouping device ID's separately by using the
sortrows()
method on the Device ID column.
However, how would I split the grouped devices into seperate tables? Currently I use the following algorithm:
for g = 1:numDevices %create a new file for each device type
outputFileIndoorData1 = sprintf("C:\Users\Documents\duetTestFile%d",g);
for h = 1:height(indoorDataSorted) %Iterate through entire CSV, splitting by device ID
if strcmp(indoorDataSorted.device_id(h),deviceIDs(g,1))
writelines(indoorDataSorted(h,1:17),outputFileIndoorData1); %Write to individual file specified
end
end
end
This is extremely resource intensive, however. What could be a more efficient way separating each devices data into a different file?
2 Comments
Image Analyst
on 29 Aug 2022
Edited: Image Analyst
on 29 Aug 2022
Please attach the output of sortrows as a variable in a .mat file so we can try things with it. Make it easy for people to help you, not hard.
In the meantime, see findgroups
Farid Barak
on 29 Aug 2022
Edited: Farid Barak
on 29 Aug 2022
Accepted Answer
More Answers (0)
Categories
Find more on Develop Apps Using App Designer 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!