How to find the difference b/w two string time and to convert in to seconds.

1 回表示 (過去 30 日間)
Manu MJ
Manu MJ 2011 年 6 月 8 日
In my code time data is as given below. eg. '12.56.13' 12.57.39'. Now how to find the difference b/w the two given time and to convert the obtained value in to seconds. How to pass the obtained seconds to timer. I am having time data of size 45 lake rows. I want efficient way to find the above.
Regards Manu M.J

採用された回答

Walter Roberson
Walter Roberson 2011 年 6 月 8 日
datenum() the strings, subtract. To convert the time difference to seconds, multiply by 24*60*60 (number of seconds in a day). To "pass" the obtained seconds to a timer, set the timer StartDelay property to that number of seconds -- and remember to start() the timer.

その他の回答 (2 件)

Jan
Jan 2011 年 6 月 8 日
More efficient than DATENUM:
t1 = '12.56.13';
t2 = '12.57.39';
t1num = [3600, 60, 1] * sscanf(t1, '%d.');
t2num = [3600, 60, 1] * sscanf(t2, '%d.');
tdiff = t2num - t1num;
I do not know what "45 lake rows" are, but you can adjust the above method to all kind of inputs.
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2011 年 6 月 8 日
if
>> t = ['12.56.13'; '12.57.39'];
then
>> tsec = arrayfun(@(x)[3600 60 1]*sscanf(t(x,:),'%d.'),1:size(t,1)).';
Manu MJ
Manu MJ 2011 年 6 月 8 日
Thank u so much.
It helped me lot.

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


Manu MJ
Manu MJ 2011 年 6 月 8 日
Datenum('12.36.15') is not functioning. Error is appearing as:
Error using ==> datenum at 174
DATENUM failed.
Caused by: Error using ==> datevec at 286 Cannot parse date 2.3.4

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by