MATLAB: Making the Trend Equal?

graphline

Line two is upside down as compared to line one
And as shown above,
I want to make Line 2 the same as Line 1.
The picture above is my guess.
Do you have any mathematical methods or other methods?
My English is not good sorry.

Best Answer

You can fit a line through curve 1. Then subtract the max of curve two and add the fitted line to it.
coefficients = polyfit(x1, y1, 1); % Fit a line.
% Get the line at locations where you have x2.
line1 = polyval(coefficients, x2);
% Find the max of curve 2.
y2max = max(y2);
% Make output curve (curve 3)
y3 = y2 - y2max + line1; % Tilt curve 2 upwards at the slant of curve 1
If you need more help, please attach the two curves in a .mat file with the paper clip icon.