Making a group of maximum nearest elements.
10 views (last 30 days)
Guillaume on 12 Mar 2020
Be aware that the following creates a temporary matrix of size numel(A) x numel(B), so if both vectors are very large you may run out of memory:
%for row vectors:
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)
%for column vectors:
A = A.'; B = B.';
assert(iscolumn(A) && iscolumn(B), 'Inputs must be column vectors')
[~, groupA] = min(abs(A.' - B), , 1)
I'm not sure how this should be applied to your example datasheet. Looking at what it contains, you should import that excel file in a table, in which case you should store the group as another variable of the table so you can then use aggregation functions such as groupsummary.