How to average plots that differ in x and y data?
1 view (last 30 days)
Hello- I currently have three different datasets that signify results of heating up 3 different specimens. Since they were carried in different times, they vary in time and value, but also differ in the number of datapoints it used.
I am trying to plot the average of the three.
Now if the number of datapoints are the same, the method is quite simple- but my case is something like:
dataset a: 2 x 10 dataset dataset b: 2 x 15 dataset dataset c: 2 x 20 dataset
but imagine they signify a temperature rise. This also starts and ends in different values.
Doing some research I also found a exchange based program called plotaverage, but it is a bit confusing for me to find out how to use it, and the example I saw of it being used was for datasets that contained the same amounts of data.
Any help will be greatly appreciated!
thank you s
Joseph Cheng on 28 Apr 2017
you can do something like
x1 = 0:.01:4;
x2 = 0:.03:5;
x3 = 0:.02:6;
y1 = sin(3*pi*x1);
y2 = sin(3*pi*x2);
y3 = sin(3*pi*x3);
time = min([x1 x2 x3]):...
min([diff(x1) diff(x2) diff(x3)]):...
max([x1 x2 x3]);
for ind = 1:3
% cut out unkown time
which you'll end up with the interpolation using pchip(), you can take a look at spline() depending on how you want to interpolate. with the set code you can code in to set the interpolated time to the shortest time, or what i show above by setting the interpolated section beyond the known with Nan's for each signal and then use nanmean() to not average them