MATLAB:曲线下的积分和阴影面积(无功能) [英] MATLAB: integrate and shade area under curve (no function)

查看:41
本文介绍了MATLAB:曲线下的积分和阴影面积(无功能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对两个已知 X 值之间的曲线下面积进行积分.索引值与实际的 x 值不对应(例如,3 秒处的数据点不在数组中的位置 3).

I need to integrate the area under the curve between two known X values. The index values do not correspond to the actual x values (e.g. a data point at 3 seconds is not at position 3 in the array).

我在尝试时意识到这一点:

I realised this when attempting:

time=[0.1,1.5,2.1,3.2,4.5,6];
traceVect=[0,0.1,1,2,3.0,2.9];
hold on
plot(time,traceVect,'k');
t0=1;
td=5;
time = time(1,[t0:td]);
traceVect = traceVect(1,[t0:td]);
area(time,traceVect,'FaceColor','g');
a = trapz(time,traceVect);

产生情节:

为了清楚起见,我需要的是:

For clarity, what I need is:

推荐答案

我的解决方案:

time=[0.1,1.5,2.1,3.2,4.5,6];
traceVect=[0,0.1,1,2,3.0,2.9];
hold on
plot(time,traceVect,'k');

%integration interval limits
t0=1;
td=5;

%select data points within the limits
ind = (time > t0) & (time < td);
xw = time(ind);
yw = traceVect(ind);

%then complete them by interpolation values at the edges
ya = interp1(time, traceVect, t0);
yb = interp1(time, traceVect, td);
xw = [t0, xw, td];
yw = [ya, yw, yb];

trapz(xw,yw)
area(xw,yw,'FaceColor','g');

这篇关于MATLAB:曲线下的积分和阴影面积(无功能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆