plot average for multiple curves with different lengths

I plotted multiple curves in the same plot and would like to calculate and plot an average of those. The problem is, that they have different lengths - meaning some have above 280 lines while others have only 120. I've found several suggestions to work with interp1, create a separate y vector and plot the average x values accordingly. However, the suggested codes that I found didn't work for me or since I'm a beginner, I wasn't really able to adapt them to my specific case.
This what I have so far:
%%load replicate measurements 1-6 in workspace
% define variables
% define 1. deployment
force = TauM1 (:,2);
depth = TauM1 (:,1);
x1 = force;
y1 = depth;
% define 2. deployment
force = TauM2 (:,2);
depth = TauM2 (:,1);
x2 = force;
y2 = depth;
...did that for all 6 measurements...
%%plot all 6 replicate deployments in one line plot
plot (x1,y1)
hold on
plot (x2,y2)
hold on
plot (x3,y3)
hold on
plot (x4,y4)
hold on
plot (x5,y5)
hold on
plot (x6,y6)
hold off
How would I be able for example to create a separate y vector from 0 to 55 and then average the interpolated x values from all 6 curves?
Thanks in advance

Answers (1)

you forgot to attach your data and screenshots of your plots. About all I can say is to sum up your 6 y signals and divide by 6.
Possible solution:
yAverage = (y1+y2+y3+y4+y5+y6)/6;
plot(yAverage, 'k-', 'LineWidth', 3);
grid on;

7 Comments

Thanks for the quick response. Unfortunately your suggestion didn't work. I've attached my data and a screenshot of my plot. As you can see, the curves go down to different depths (y values).
Why do you have non-unique values in your data? Even if I assume the x axis is vertical and the y axis is horizontal, you have some x axis values that are in there twice so there are two y values (horizontal) for a single x (vertical) value.
I attached what I've done so far but ran into that problem with your data.
Thanks for your effort. Your approach was exactly what I had in mind as well. The multiple force values for the same depth values were due to how the measuring device was working... So I assume, that as long as my values aren't monotonic increasing there is no way to interpolate and average them? Maybe averaging the data isn't the best approach then after all... Thank you for your time though!
Well you can - it just takes extra work. Plus you also have to keep track of how many signals there are at each point. Notice how there are all the signals at a depth of up to 5, but fewer and fewer signals to average as you get down to depths of 25 to 40. So you can't divide by 6 everywhere. Do you still want to do this?
Yes, that's what I meant with different lengths of the curve in my initial question. Sorry, that probably wasn't clear enough. How would I average only those curves that actually show a signal at that depth?
Just check if the xAxis values are more than the max x for each signal.
Thank you for your help. I will get back to this question if I make any progress.

Sign in to comment.

Asked:

on 4 Sep 2018

Community Treasure Hunt

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

Start Hunting!