MATLAB: Averaging fluctuating curves in a single one

MATLAB: Averaging fluctuating curves in a single one

averagingcurve averagingMATLAB

I have these curves as results from different cases.
I want to make an average curve around which these curves fluctuate to express the whole data in a single average curve. How?

Best Answer

  • Assuming they all have values at the same set of x coordinates, just average them:
    yMean = (y1+y2+y3+y4+y5+y6+y7+y8+y9) / 9;
    or if they’re row vectors:
    yMean = mean([y1;y2;y3;y4;y5;y6;y7;y8;y9], 1);
    If they’re column vectors, use commas and 2:
    yMean = mean([y1,y2,y3,y4,y5,y6,y7,y8,y9], 2);
    If the curves have different x vectors, then you’ll have to interpolate them using a common set of x values
    x = unique([x1(:);x2(:);x3(:);x4(:);x5(:);x6(:);x7(:);x8(:);x9(:)]);
    y1 = interp1(x1(:), y1(:), x(:)); % y1 will be a column vector.
    That should work for both row vectors or column vectors. Repeat for the other data vectors.
  • Add a Comment

    Your email address will not be published. Required fields are marked *