least squares fit

Hi, I have two data sets that share the same x values. After plotting both of these on the same graph, I want to find the value of a scalar that I have to multiply one of the y value sets to equal the second set. Im assuming some kind of least squares function or minimisation is required , but am not too sure how to implement it.

 Accepted Answer

John D'Errico
John D'Errico on 17 May 2011
As long as they share the same x values, there is no problem. Given two vectors y1 and y2, compute the coefficient K such that K*y1 = y2 as closely as possible as:
K = y1(:)\y2(:);
This does a linear least squares to solve your calibration problem. Had the curves different x values, it would have been more difficult.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!