plot average for multiple curves with different lengths
6 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Image Analyst
on 4 Sep 2018
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
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!