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)
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??

Accepted Answer

Walter Roberson
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
nihed sboui
nihed sboui on 28 Feb 2020
@walter yes all the curves have the same number of points and they are relative order with the same x .
i have to find the one that matches the most the fixed curve .i think i have to find the curve that contain the maximum of number of points that are quite close of my fixed curve's points .
Walter Roberson
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.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!