【问题标题】:MATLAB: integrate and shade area under curve (no function)MATLAB:曲线下的积分和阴影区域(无功能)
【发布时间】:2016-09-15 07:03:34
【问题描述】:

我需要对两个已知 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);

这会产生情节:

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

【问题讨论】:

    标签: arrays matlab indexing plot area


    【解决方案1】:

    我的解决方案:

    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');
    

    【讨论】:

      猜你喜欢
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 2013-10-10
      • 1970-01-01
      • 2017-05-28
      • 1970-01-01
      相关资源
      最近更新 更多