MATLAB: Scale one scattered dataset to fit another scattered dataset

curve fittingpoint matching algorithms

I have two datasets of scattered points. Dataset 1 is defined by (x,y) where x and y are column vectors. Dataset 2 is defined by (z,t) where z and t are column vectors. The four column vectors are of the same size. I would like to scale dataset 1 by a factor (which I do not know) such that the scaled result is the best fit to dataset 2. I do not have a function that defines either datasets so I cannot use lsqcurvefit because I do not have the function "fun".
Is it possible to do the above with Matlab?

Best Answer

Sure, your "equation" to minimize in least-squares sense is D1(x,y)-k*D2(t,z)
function sse=sseval(k,D1,D2)
and use that as the functional for fminsearch. It expects a function of only the one vector, x, of unknown coeffiecients so define an anonymous function that incorporates the data in it --
fun = @(x) sseval(x,D1,D2);
the values of D1, D2 in the workspace at the time of the definition of fun are embedded into the function definition itself automagically.
x0=1; % starting guess; perhaps the rms ratio of the two would be better if far from 1