Find elements from a matrix and sum variables from other matrix

조회 수: 2 (최근 30일)
nlm
nlm 2019년 2월 9일
댓글: nlm 2019년 2월 10일
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.

채택된 답변

Matt J
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,:),
  댓글 수: 2
nlm
nlm 2019년 2월 9일
array2table and group summary did the trick I was looking for. Thanks alot.
nlm
nlm 2019년 2월 10일
I have a matrix of lat lon count, where for same lat lon, the count variable range between 1 to 4.
I need to have something like this,
LAT LON cnt = 1 cnt=2 cnt=3 cnt =4
12.4 91.4 1 0 3 0
31.4 45.6 2 4 0 9
45.9 91.5 10 0 9 20
I tried table, I could not figure out.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
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]);
  댓글 수: 1
nlm
nlm 2019년 2월 9일
This issued an error,
"Error using accumarray
Requested 391384x391384 (1141.3GB) array exceeds maximum array size preference."

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by