Load textfile into Matlab

Hello,
I have the following textfile (see figure).
The first line says 'eating'. The second line is the time when eating occured. The time is given like 00:00:00.001, in hours:minutes:seconds(also with decimals).
I've been looking for some scripts to load this into Matlab, but I can't seem to find an answer that doesn't give me NaN or zeroes...
Thanks!textfile.png

댓글 수: 5

Stephan
Stephan 2019년 8월 21일
please attach an example file
Stephen23
Stephen23 2019년 8월 21일
편집: Stephen23 2019년 8월 21일
@Sam: please upload a sample file by clicking the paperclip button.
textscan could probably do this, without parsing each line separately or importing the file as text first. But we need a sample file to work with!
Rik
Rik 2019년 8월 21일
It is probably the best to load the entire file as text and then parse the activity lines separately from the timestamps.
What code have you tried?
Sam
Sam 2019년 8월 21일
I have tried this code
filename = 'DAY12_153521_160521_1_20S_kip5.txt';
[A,delimiterOut]=importdata(filename)
But this gives NaN values. What do you mean by parse the activity lines seperately from the timestamps? There are already 2 different lines for these two?
Thanks for the quick answers.
Rik
Rik 2019년 8월 21일
You need to read the file as a text file. To do this, you can use several functions. One of the functions you could use is my readfile function. The benefit of that function in this case is that it already returns your file as a cell array (one cell per line). This makes it trivial to separate the activity from the time:
filename = 'DAY12_153521_160521_1_20S_kip5.txt';
data = readfile(filename);
%use a step size of 3 to account for the empty lines
activities=data(1:3:end);
timeinfo=data(2:3:end);
Now you have a cell array for both, so you can parse them separately.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

태그

질문:

Sam
2019년 8월 21일

댓글:

Rik
2019년 8월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by