Finding an average curve

조회 수: 13 (최근 30일)
Siobhan
Siobhan 2012년 3월 5일
댓글: Muhammad Irfan 2014년 2월 25일
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

채택된 답변

Matt Tearle
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
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
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?

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by