matlab - 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
包括到其他峰并且仍然接近目标?
解决方案
推荐阅读
- webpack - 如何在没有 HTML 的情况下加载带有哈希的 webPack 包?
- javascript - 更改功能内的光滑滑块功能不起作用
- php - 如何从 PHP 7 中的嵌套包含文件中跳出 while 循环?
- asp.net-core - 使用 Angular 6 ag-grid 和 ASP.NET 和 EF Core 2.1 进行服务器端过滤
- android - 在 ListView 中显示特定于 Firebase 的子数组项
- angular - 如何将生成的唯一 ID 从推送功能复制到子 ID(firebase)
- python - 如何在不下载扩展程序的情况下编写 Chrome 浏览器扩展程序 ID 和权限?
- java - SpringBoot:为代理GET请求创建请求工厂
- php - php - 如何从数组对象中获取值
- javascript - 如何在页面加载时从 div 标签中获取 id 并将其设置为活动状态?