필터 지우기
필터 지우기

If I have three graphs and I want to place them over one another so that their mean values align, and then want to create a trend line among those graphs how would I do this?

조회 수: 2 (최근 30일)
%example
x=[1:0.03:500];
y=x^4;
i=[100:0.01:600];
y2=x^2+30;
plot(x,y,i,y2);
  댓글 수: 1
Adam Danz
Adam Danz 2018년 7월 13일
편집: Adam Danz 2018년 7월 13일
Your example doesn't work.
What do you mean by aligning their mean values? Do you mean for each line you'd like to subtract the mean?
x = x-mean(x);
y = y-mean(y);

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

채택된 답변

Image Analyst
Image Analyst 2018년 7월 14일
Try this:
x1=[1:0.03:500];
y1 = x1.^4;
x2 = [100:0.01:600];
y2 = x2.^2+30;
plot(x1,y1, 'r-', 'LineWidth', 2);
hold on;
plot(x2,y2, 'b-', 'LineWidth', 2);
grid on;
xAll = [x1, x2];
yAll = [y1, y2];
[coefficients, S, mu] = polyfit(xAll, yAll, 1)
numPoints = max([length(x1), length(x2)])
fittedX = linspace(min(xAll), max(xAll), numPoints);
fittedY = polyval(coefficients, fittedX, S, mu);
plot(fittedX, fittedY, 'g-', 'LineWidth', 2);
legend('y1', 'y2', 'linear fit y', 'location', 'north');
Is that what you're thinking of? Note that because you have more of the flatter curve points, it's pulling down the "average" line curve. If you don't want that you can use interp1 to resample to have them both have the same number of points and same starting and ending x values.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by