Hello every body I have multiple xy curves extacted from experiments results (X1 vs Y1, X2 vs Y2,......X5 vs Y5), I looking for method to plot the Xavg vs Yavg. Thanks

 채택된 답변

Star Strider
Star Strider 2016년 6월 19일

3 개 추천

Use interp1.

댓글 수: 4

abdullah algarni
abdullah algarni 2016년 6월 19일
Hi Star Strider Thank You for your answer, but I am beginner with Matlab i need more clarification (How i can use interp1)
My pleasure.
If you want to average the curves, you have to average them at the same x-values. So set up an appropriate vector for the x-values (none of the curves have to have those values), then use that vector with the x and y values for each curve, and use interp1, to interpolate to create a common set of points on the curves, then average them at those points.
I would do something like this:
x1 = sort(rand(1, 10)); % Create Data
y1 = rand(size(x1)); % Create Data
x2 = sort(rand(1, 15)); % Create Data
y2 = rand(size(x2)); % Create Data
xi = linspace(0, 1, 50); % Create Vector Of Common X-Values
y1i = interp1(x1(:), y1(:), xi(:), 'linear', 'extrap'); % Interploate Or Extrapolate To New ‘x’ Values
y2i = interp1(x2(:), y2(:), xi(:), 'linear', 'extrap'); % Interploate Or Extrapolate To New ‘x’ Values
y_mean = mean([y1i y2i], 2); % Mean Of Y Values
figure(1)
plot(x1, y1, '-b')
hold on
plot(x2, y2, '-g')
plot(xi, y_mean, '-r', 'LineWidth',2)
hold off
grid
legend('Data 1', 'Data 2', 'Data Mean', 'Location','N')
Soraya Ghassemlou
Soraya Ghassemlou 2021년 9월 6일
how would you do this for 50 curves?
Star Strider
Star Strider 2021년 9월 6일
I would use a for loop.
The code would have to be changed to accommodate that, and to put the curves in a cell array and then index them as such in the loop and then average them (since the point here is that the curves have different dimensions, and so would not be in a matrix).
It also assumes that the ‘x’ vectors cover the same range (initial and final values), so the interpolation would simply equalise the number of elements in each of them, and the associated ‘y’ vectors. If that were not the situation, this would become more complicated, and likelly considerably so.
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

질문:

2016년 6월 18일

댓글:

2021년 9월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by