Hi. I need your help. I try to calculate area of each peaks event, but I always got an error.
%%Peak flow analysis 2 (Figure 3)
flowtable = finalCSVnew(:,[1,7:8]); % create table containing DateAndTime, Durchflusslm, and SummeaktuellerTagm data
peakflowEvent = flowtable{:,2} > 3 ; % determine the threshold of flow(m3/h) for peakflowEvent
% use false as logical vector to determine transition. With function diff,
% transitions from false (0) to true (1) will be 1 and transitions from true
% to false will be -1. This will be 1 at the start of a dry period and -1 after the end
peakTransitions = diff([false; peakflowEvent; false]); eventStarts = find(peakTransitions == 1);eventEnds = find(peakTransitions == -1) -1;% define the peak flow of each event through the flow data (peakflow) and
% the time when peak flow is happened (peakflowtime)
[peakflow, peakflowlocrel] = arrayfun(@(s, e) max(flowtable.Durchflusslm(s:e)), eventStarts, eventEnds);peakflowlocabs = peakflowlocrel + eventStarts - 1;peakflowtime=flowtable.DateAndTime(peakflowlocabs);% create result table containing start and end time for peak flow event, the duration
% between start and end time, and peak flow
peakflowanalysis2 = table(flowtable.DateAndTime(eventStarts), flowtable.DateAndTime(eventEnds), ... flowtable.DateAndTime(eventEnds) - flowtable.DateAndTime(eventStarts), ... peakflow, peakflowtime, ... 'VariableNames', {'Start', 'End', 'Duration','PeakFlow','PeakFlowTime'});volume=trapz(flowtable.Durchflusslm(flowtable.DateAndTime(eventStarts):flowtable.DateAndTime(eventEnds)));
It got an error on the last function to determine volume with trapz "Input must be scalars". Do you know how to properly use trapz for calculating area of each peak event? I have been trying since morning to solve this, but I always got an error. I would really appreciate for your help.
Best Answer