Split one CSV file in 4 parts
Ältere Kommentare anzeigen
Hello,
I would like to know, how can I split a CSV file in 4 parts ? As you can see attached, there is a CSV file from an accelerometer plotted and I would like to split it in 4 parts. You can also find attached the program that I'm using to plot the file (test4.m).
First part: Between 0 to 12 seconds called "entering"
Second part: 12 to 118 seconds called "preparing"
Third part: 118 to 395 seconds called "drinking"
Fourth part: 395 to the end called "exiting"
The thing is that the time on x axis (in seconds) is converted from the timestamp of the accelerometer. (you can find the CSV used attached)
Save these parts in 4 different CSV files
Thank you for your help.
(MATLAB R2018b)
2 Kommentare
Bob Thompson
am 24 Mai 2019
I don't have the ability to look at the input files, sorry, but can you tell me if the number of rows for the two files is 1-1? Do you have one set of data for each time, and one time for each set of data?
If this is the case then I would suggest reading both files into matlab and just doing a split based on indexing. Something like this:
data = csvread('datafile.csv');
time = csvread('timefile.csv');
entering = data(time<=12);
preparing = data(time>12&time<=118);
drinking = data(time>118&time<=395);
exiting = data(time>395);
If you have time information in a datetime format, then the operation is much the same, you just need to convert it to datetime first.
Pierre
am 24 Mai 2019
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!