Converting datenums to get time durations

1 回表示 (過去 30 日間)
Joy Shen
Joy Shen 2021 年 11 月 23 日
コメント済み: Peter Perkins 2021 年 11 月 24 日
I need the time durations that the component is in operation, above a certain height. The time is in 24 hour time. So essentially I want to end up with a matrix with one column that has the component ID and another column with time durations for each component. Any advice?
% Load excel
data=xlsread('file.xlsm');
%%
CompID = data(:,1);
Date = data(:,8);
Height = data(:,10)
%% Converting datenum to datetime
Date = datetime(Date,'ConvertFrom','yyyymmddHHSS');
%%
H = 3;
i = WaveHeight>H;
ThreshH = Height(i);
ThreshDate = Date(i);
ThreshID = CompID(i);

回答 (1 件)

Chris
Chris 2021 年 11 月 24 日
I don't see where WaveHeight is declared, but you can calculate a duration by subtracting datetimes.
ThreshDate = datetime('now');
pause(1);
newDate = datetime('now');
dur = newDate-ThreshDate
dur = duration
00:00:01
To get the answer in seconds (similarly for minutes or hours):
converted = seconds(dur)
converted = 1.0100

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by