Sum calendar Duration array
6 ビュー (過去 30 日間)
古いコメントを表示
Hi Guys,
I have two arrays in the datetime format. 1 array with the starting points of an event, a 2nd array with the end points of the same event. Using the "between" function I have determined the times between the start and end of each event. Now resulting in 1 array with calendarDuration values.
My goal is to find the total duration, thus summing up all values in the calendarDuration array. However... The sum function does not work for this format, see the code resulting in the error below. Any help on how to sum up the values with calendarDuration format?
Error using sum
Invalid data type. First argument must be numeric or logical.
threshold=1.5;
exceed_RH=Druk_RH>1.5; %logical array for threshold exceedance
difference_RH=diff(exceed_RH);
start_operation_RH=difference_RH==1;
time_start_operation_RH=time(start_operation_RH); % Returns array with datetimes of start of operation
end_operation_RH=difference_RH==-1;
time_end_operation_RH=time(end_operation_RH); %Returns array with datetimes of end of operation
dt=between(time_end_operation_RH,time_start_operation_RH); %time between start and end, calendarDuration format
total_uptime_RH=sum(dt)
0 件のコメント
採用された回答
Guillaume
2020 年 1 月 9 日
Are you actually interested in getting the result as a calendarDuration as opposed to plain duration? Indeed, for some reason sum is not implemented fo calendarDuration. It is for duration though.
I assume that you actually don't want calendarDuration, which is useful if you want to express elapsed time in terms of years, months or weeks but not so useful for ellapsed time in hours, minutes, seconds. For that you're better served with plain duration. In that case:
dt = time_end_operation_RH - time_end_operation_RH; %plain duration array
total_uptime_RH = sum(dt);
If you do want a calendarDuration result, you'll have to perform the sum in a loop:
dt = between(time_end_operation_RH, time_start_operation_RH);
total_uptime_RH = 0;
for idt = 1:numel(dt)
total_uptime_RH = total_uptime_RH + dt(idt);
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!