Split one CSV file in 4 parts
이전 댓글 표시
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
Bob Thompson
2019년 5월 24일
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
2019년 5월 24일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!