Upload txt file with time units
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have a text file like,
13:43:51 26.0503 0.0000060763786
13:43:51 26.0503 0.0000085937353
13:43:51 26.0503 0.0000073350570
13:43:51 26.0503 0.0000073350570
13:43:52 26.0503 0.0000084201246
13:43:52 26.0503 0.0000072482512
13:43:52 26.0503 0.0000076388760
13:43:52 26.0503 0.0000093315811
13:43:52 26.0503 0.0000073350570
I would like to upload the time difference from the beginning, such as
1 26.0503 0.0000060763786
1 26.0503 0.0000085937353
1 26.0503 0.0000073350570
1 26.0503 0.0000073350570
2 26.0503 0.0000084201246
etc.,..
That is have the time display in seconds only. Any idea how to do this.
When using x = load('data.txt');
I get
14.0000 24.9678 0.0008
14.0000 24.9678 0.0008
14.0000 24.9678 0.0008
14.0000 24.9678 0.0008
14.0000 24.9678 0.0008
14.0000 25.0020 0.0008
It seems to only take the first number.
Kind Regards,
That is I want to upload a vector of hh:mm:ss and then convert it to seconds.
0 个评论
回答(1 个)
Walter Roberson
2013-5-24
fid = fopen('data.txt','rt');
datacell = textscan(fid, '%s%f%f');
fclose(fid);
datatimes = datenum(datacell{1}, 'hh:mm:ss');
timeoffset = datatimes - datatimes(1);
offsetsecs = round(timeoffset * 24*60);
newdata = [offsetsecs(:), datacell{2}, datacell{3}];
newdata will now be the array.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!