Combining curves to create a single average curve

128 次查看(过去 30 天)
Hi, I've got some data from an experiment that has been repeated three times. I'd like to plot the average of the curves. However, for each replicate the number of and the value of X and Y differs. I was wondering what the best approach is for dealing with this? I've tried to interpolate by using a common x scale but run into difficulties was the number of Y vallues differ.
I'm very new to matlab and anyhelp would be greatly appreciated!
Thanks
  1 个评论
Jan
Jan 2016-10-28
If you post what you have tried, suggesting an improvement would be much easier and more likely to match your current code.

请先登录,再进行评论。

回答(2 个)

Jan
Jan 2016-10-28
编辑:Jan 2016-10-28
Interpolation is the correct approach:
% Test data:
x1 = linspace(0, 2*pi, 100);
y1 = sin(x1) + rand(size(x1)) * 0.2 + 0.1;
x2 = linspace(0, 2*pi, 110);
y2 = sin(x2) + rand(size(x2)) * 0.2;
x3 = linspace(0, 2*pi, 120);
y3 = sin(x3) + rand(size(x3)) * 0.2 - 0.1;
% Interpolate to get same time resolution:
x = linspace(0, 2*pi, 200);
yy1 = interp1(x1, y1, x);
yy2 = interp1(x2, y2, x);
yy3 = interp1(x3, y3, x);
y = mean([yy1; yy2; yy3], 1);
axes('NextPlot', 'add'); % as: hold on
plot(x1, y1, 'r', x2, y2, 'g', x3, y3, 'b', x, y, 'k')
  3 个评论
Khaoula Ouazzani
Khaoula Ouazzani 2023-3-28
@Jan thank you for the information (eventhough I read it years later lol).
I have anoter question: what if my data has got different xi (I can't interpolate relatively to one X)?

请先登录,再进行评论。


KSSV
KSSV 2016-10-28
clc; clear all ;
t = linspace(0,2*pi) ;
x1 = 0.1*sin(t) ;
x2 = 0.15*sin(t) ;
x3 = 0.2*sin(t) ;
%
hold on
plot(t,x1,'r') ;
plot(t,x2,'b') ;
plot(t,x3,'g') ;
%%calculate average
xavg = (x1+x2+x3)/3 ;
plot(t,xavg,'k')
  2 个评论
Jan
Jan 2016-10-28
This does not consider the detail "the number of and the value of X and Y differs".
KSSV
KSSV 2016-10-28
Numbers can be brought to equal number using interpolation.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by