Making a group of maximum nearest elements.
6 ビュー (過去 30 日間)
古いコメントを表示
If I have some points and a data. I need to find the all the nearest elements of points. How can I do that ? Please help me.
2 件のコメント
採用された回答
Guillaume
2020 年 3 月 12 日
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:
%example data
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:
%demo data
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.
10 件のコメント
Guillaume
2020 年 3 月 17 日
As I've said, this is typically a bad idea. I was asking about what you want to do after that. It is very likely that whatever it is, it will be much easier if you don't do this.
Now if you really insist:
group = accumarray(a(:), groupnumber(:), [], @(v) {v});
or
group = splitapply(@(v) {v}, a(:), groupnumber(:));
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!