find the number of seconds between two times

3 ビュー (過去 30 日間)
captainmariah
captainmariah 2016 年 8 月 8 日
コメント済み: captainmariah 2016 年 8 月 8 日
One time comes from a vector, date (which I only want the first date) and the other one is a string form.
time0 = datenum(date(1),'HH:MM:SS.FFF');
time1 = datenum('12:35:00','HH:MM:SS');
past_time1=etime(time1,time0);
but I get an error when I run this: Index exceeds matrix dimensions.
Error in etime (line 40)
t = 86400*(datenummx(t1(:,1:3)) - datenummx(t0(:,1:3))) + ...
Error in processdata (line 107)
past_time1=etime(time1,time0);
Why isn't this working?
date(1) contains the value '12:31:45.115'

回答 (1 件)

Adam
Adam 2016 年 8 月 8 日
編集済み: Adam 2016 年 8 月 8 日
date(1) cannot contain a full string. If date is that string then date(1) is just '1'. Alternatively if date is a cell array you want data{1} instead.
Also do not call your string 'date', you are obfuscating a builtin function which may also be the cause of your error if it is being called from inside another function.
  1 件のコメント
captainmariah
captainmariah 2016 年 8 月 8 日
I think I solved the problem with 'datevec'. date(1) contains a string with format hh:mm:ss.fff.

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

カテゴリ

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