【发布时间】:2017-11-06 15:20:16
【问题描述】:
我是 matlab 的新手,在计算峰下面积时遇到问题。以下是我用来查找峰值的代码:
%% Peak flow analysis 2 (Figure 3)
flowtable = finalCSVnew(:,[1,7:8]); % create table containing DateAndTime, Durchflusslm, and SummeaktuellerTagm data
peakflowEvent = flowtable{:,2} > aa ; % 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'});
numPeakflow2 = height(peakflowanalysis2); % calculate the number of max flow
% plot flow and peak flow
figure(3)
plot(flowtable.DateAndTime,flowtable.Durchflusslm,flowtable.DateAndTime(peakflowlocabs),peakflow,'v','MarkerFaceColor','red',...
'MarkerSize',5)
xlabel('Date and Time'); % define Date and Time as x-axis
ylabel('Flow [m3/h]'); % define Flow as y-axis
title('Peak Flow Events (2)'); % define the title of the plot
legend('Flow','Peak Flow','Location','Northeast','Orientation','Vertical')
grid on % show grid on plot
datacursormode on % enable to display data value interactively in the plot
% clear temporary variables
clearvars peakflowEvent peakTransitions eventStarts eventEnds peakflowlocrel peakflowlocabs peakflow peakflowtime
它产生两张表和一张图。包含峰值并代表每个事件的图形。峰数=事件数 该表包含原始数据: 下表包含过滤后的数据,它们有峰值
我想知道如何计算每个事件(11 个事件)的峰下面积,而不是所有事件的总和。我阅读了关于 trapz() 的内容,但我很困惑如何将它应用于多个峰值。请你帮助我好吗?非常感谢您的帮助。
【问题讨论】:
标签: matlab matlab-figure matlab-guide