A = [1,4,2,6,9,0,4.2,5.6];
B = [0.1,4.1,3];
assert(isrow(A) && isrow(B), 'Inputs must be row vectors');
[~, groupA] = min(abs(A - B.'), [], 1)
A = A.'; B = B.';
assert(iscolumn(A) && iscolumn(B), 'Inputs must be column vectors')
[~, groupA] = min(abs(A.' - B), [], 1)
2 Comments
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510378-making-a-group-of-maximum-nearest-elements#comment_808673
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510378-making-a-group-of-maximum-nearest-elements#comment_808673
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510378-making-a-group-of-maximum-nearest-elements#comment_808885
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510378-making-a-group-of-maximum-nearest-elements#comment_808885
Sign in to comment.