MATLAB: Least squares fit

minimise difference

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.

Best Answer

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.