Find elements from a matrix and sum variables from other matrix
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have a matrix of lat long (406, 964) say A, and B. I also have a huge matrix of length 36000 and 3 variables (lat, long, intensity), say C. The lat lon in C have repeated values. I need to find only the elements of A and B that match in C, but also sum the intensity values of all those matching coordinates.
Thank you. Look forward to you help.
0 件のコメント
採用された回答
Matt J
2019 年 2 月 9 日
T=array2table(C);
Gs = groupsummary(T,{'C1','C2'},@sum);
Gs = table2array(Gs(:,[1,2,4]));
bool=ismember(Gs(:,1),A) & ismember(Gs(:,2),B);
result=Gs(bool,:),
その他の回答 (1 件)
Matt J
2019 年 2 月 9 日
Na=numel(A);
Nb=numel(B);
[~,Ia]=ismember(C(:,1),A(:));
[~,Ib]=ismember(C(:,2),B(:));
result = accumarray([Ia,Ib],C(:,3),[Na,Nb]);
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!