Finding an average curve
22 ビュー (過去 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!