Upload txt file with time units
이전 댓글 표시
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.
답변 (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.
댓글 수: 1
카테고리
도움말 센터 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!