Finding an average curve
19 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Matt Tearle
2012-3-5
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 个评论
Muhammad Irfan
2014-2-25
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
更多回答(1 个)
Image Analyst
2012-3-5
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?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!