フィルターのクリア

Reading a text file containing colon mark

4 ビュー (過去 30 日間)
Mohammed Qahosh
Mohammed Qahosh 2019 年 5 月 30 日
コメント済み: Mohammed Qahosh 2019 年 6 月 6 日
I have a text file (a) contains words and numbers and colons. I would like to use the fscan and the fread function to get a time. However, the time is like this 2:30:20
I wonder, how can I do that such that there are cono(:) marks in between.
B=fread(a,time,'uint16');
I think the problem is in the uint16, but I don't know how to solve that.
Thanks in advance for your help
  1 件のコメント
Rik
Rik 2019 年 5 月 30 日
Have you read the documentation for fread?

サインインしてコメントする。

回答 (1 件)

Krishna Anne
Krishna Anne 2019 年 5 月 30 日
Looks like you are getting the time as "Duration" class, Try one of these as required to fetch hours or seconds or minutes or milliseconds etc.
milliseconds(time) or
seconds(time) or
hours(time) or
minutes(time)
..........etc, provided time has class 'duration' you may check by typing class(time)
  16 件のコメント
Rik
Rik 2019 年 6 月 3 日
編集済み: Rik 2019 年 6 月 3 日
Please attach the file itself, not a text copy. Use the paperclip icon to attach it to a comment.
Mohammed Qahosh
Mohammed Qahosh 2019 年 6 月 6 日
Dear Rik, thank you very much for your help, and sorry for my late response I was so busy.
Actually, I added the following code to the original one and it works :
A=regexp(text,'Time');
B=regexp(text,'Height');
L=B-A(1);
if L==16
C=strfind(text,'Time');
time_hour=str2num(text(C(1)+7:strfind(text,'Height')-8));
time_min=str2num(text(C(1)+10:strfind(text,'Height')-5));
time_hour=str2num(text(C(1)+13:strfind(text,'Height')-3));
time=60*60*time_hour+60*time_min+time_sec;
end
% % I also changed the length L based on the time and it worked

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by