Sum calendar Duration array
조회 수: 8 (최근 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!