Load textfile into Matlab
1 次查看(过去 30 天)
显示 更早的评论
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!
5 个评论
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!