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
답변 (1개)
Image Analyst
2018년 9월 4일
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
Isabel Schreiber
2018년 9월 4일
Image Analyst
2018년 9월 4일
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.
Isabel Schreiber
2018년 9월 4일
Image Analyst
2018년 9월 5일
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?
Isabel Schreiber
2018년 9월 5일
Image Analyst
2018년 9월 5일
Just check if the xAxis values are more than the max x for each signal.
Isabel Schreiber
2018년 9월 5일
카테고리
도움말 센터 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
