我需要将曲线下的区域整合到两个已知的X值之间。索引值不对应于实际x值(例如,3秒处的数据点不在阵列中的位置3)。
我在尝试时意识到这一点:
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);
产生情节:
答案 0 :(得分:0)
我的解决方案:
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');