首页 > 解决方案 > trapz 函数仅适用于有限的 x 范围

问题描述

我想整合具有某些峰值的时间序列数据(河浪),但我只需要最高峰的积分。

我有一个积分应该满足的预定义区域,我更改了一个 y 轴阈值来实现这个区域。

上一个问题更详细地描述了原始问题:Integration returned required y value for predefined area在Wolfie的帮助下,开发了代码来回答这个问题。

现在的问题是,当我不想整合其他峰时,我也会整合

到目前为止的代码:

x = Q(:,1); %
y = Q(:,2); %

target = 17.4e+06;  % Target area = Polder Volume

yi = max( y );      % Initialise yi to be max possible y
dy = 10;            % Step change in yi

Ai = 0;             % Area first iteration
thresh = 10000;     % Threshold for stopping loop
while target - Ai > thresh && yi >= min(y)
    yi = yi - dy;
    ix = y >= yi;
    % Approximate integral above the line
    Ai = trapz( x(ix), y(ix) - yi );
end
figure(e); clf; hold on

plot( x, y );
patch( x(ix), y(ix), [1,0.5,0.5], 'facealpha', 0.5 );
plot( x, ones(size(x))*yi, '--', 'linewidth', 2 )
xlim( [min(x),max(x)] ) 

结果是:

不可缺少的

如果应用于具有多个峰值的数据。

总之:

如何确保只有最大的峰被积分截断?我怎样才能防止Ai包括到其他峰并且仍然接近目标?

标签: matlabintegrationarea

解决方案


推荐阅读