Finding an average curve

13 views (last 30 days)
Siobhan
Siobhan on 5 Mar 2012
Commented: Muhammad Irfan on 25 Feb 2014
Hi!
Just wondering does anybody know the best way to find the average curve from a group of curves using matlab?
I have been using excel to first find the trendline of each curve. I have then subbed in x=1,2,3 etc to find the corresponding y values for each graph. I then average all the y values and plot them against my x values. It is a very very long and tedious method as i have lots and lots of data.
I hope somebody knows a better way to do it in matlab and is willing to share! I should mention i am a matlab newbie!
Thanks
Siobhan

Accepted Answer

Matt Tearle
Matt Tearle on 5 Mar 2012
When you say "find the trendline of each curve" I assume you mean that you have several sets of (x,y) data and you're doing a (linear?) fit to each of those sets? If so, forget Excel and just do the whole lot in MATLAB!
% Make some pretend data
% Each row is a data set
x = (0:5)';
y = [3 + 2*x,3.2 + 1.6*x,2.6 + 2.2*x] + 0.2*randn(6,3);
% Make design matrix
M = [x,x.^0];
% Solve for coefficients
C = M\y;
% Evaluate fits
yfit = M*C;
% Take average of fits
avgyfit = mean(yfit,2);
% See the results
plot(x,y,'x')
hold on
plot(x,yfit)
plot(x,avgyfit,'k','linewidth',2)
  1 Comment
Muhammad Irfan
Muhammad Irfan on 25 Feb 2014
Dear Matt,
Can you also advise that If I have a set of plots i.e. I have functions for each of those plots, what would be the quickest way to estimate the average of those plots from the functions? and can i get the corresponding function of that plot.
I hope you understand my question

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 5 Mar 2012
If you have the same number of x values for every y curve, and you have all the y values in rows in a 2D array (each row is a y curve and columns are the y's at the x values), then you can simply do
yMean = mean(y);
If your curves are in columns instead of rows, use this
yMean = mean(y, 2);
wouldn't that do what you want?

Categories

Find more on Spline Postprocessing in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!