How to fit the best line
2 views (last 30 days)
Show older comments
Hello,
I have a problem trying to choose out of two vectors the one vector that is most similar to a sample vector. My function receives a couple of vectors and a sample vector every time. It then needs to compare each one of them to the sample, and choose the best fit. The vectors represent lines and the values in each vector represent the line's dots, so actually I need to fit the best line pattern to the sample.
My problem is that sometimes I need to fit a vector of zeros to a vector of very small values. So, for example if the two vectors are: a = [ 0 0 0 ] ; b= [2 1 1] and the sample is c = [ 0.001 0.001 0.001], I would like to get 2 coefficients, according to which I will be able to decide that the 'a' vector is the better fit. The basket case is, I cannot use xcorr(a,c,0,'coeff') function or corrcoef, since a vector of zeros will not give me a correlation coefficient, but will present NaN result instead.
I will also mention that the two vectors and the sample are the outcome of robustfit function, so actually I can use the lines' coefficients rather than the actual point vectors and call them through the function, if you guys think it's easier/better.
What do I do?
0 Comments
Accepted Answer
Tom Lane
on 27 Sep 2012
Would it be reasonable to compare norm(a-c) with norm(b-c)?
3 Comments
Tom Lane
on 29 Sep 2012
There is a pdist2 function in the Statistics Toolbox and you can use it to compute the cosine distance. However, as you point out, the cosine to the zero vector is undefined. I'm not sure how you would quantify your notion that the zero vector is "closer" to a vector with small elements, but other vectors have a distance related to the angle between them.
More Answers (0)
See Also
Categories
Find more on Hypothesis Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!