hi , i have two graph one is fixed and the other one is changing (64 graphe )i want to find the most closest graphe to the fixed one .please help??
2 views (last 30 days)
Show older comments
nihed sboui
on 27 Feb 2020
Commented: Walter Roberson
on 28 Feb 2020
hi , i have two graph one is fixed and the other one is changing i want to find the most close graphe to the fixed one .please help??
2 Comments
Accepted Answer
Walter Roberson
on 27 Feb 2020
One approach is to use https://www.mathworks.com/help/stats/knnsearch.html knnsearch . That would get you a list of the closest point in the fixed to each point in the varying, and you could then find the minimum distance from there.
Another approach, assuming Euclidean distance:
dsq = bsxfun(@minus, xvarying(:), xfixed(:).').^2 + bsxfun(@minus, yvarying(:), yfixed(:).').^2;
mindsq = min(dsq(:));
[varying_idx, fixed_idx] = find(dsq == mindsq);
Then it is the case that for each element in varying_idx, x(varying_idx(K)), y(varying_idx(K)) is the closest point to x(fixed_idx(K)), y(fixed_idx(K))
The reason why there can be multiple elements in varying_idx is that it is possible that there are two different points that are exactly as far as each other to their closest corresponding points in the fixed curve.
5 Comments
Walter Roberson
on 28 Feb 2020
All_residue = sum((all_varying_y - fixed_y).^2), 2);
[~, best_curve_idx)] = min(All_residue)
This assumes that the fixed_y is a row vector and that all_varying_y is a 2d array with any one curve being along the row.
This algorithm does not count the number of points that are "quite close" the way you asked. Instead it calculates sum of squared distance. For example if you had a curve in which the first three y were quite far away but the rest were nearly identical to the fixed curve, then the number that are nearly the same would be high, but the three points that are wildly different would result in quite an overall difference.
More Answers (0)
See Also
Categories
Find more on Smoothing 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!