# Find corresponding values for unique values in a matrix

3 Ansichten (letzte 30 Tage)
SChow am 14 Feb. 2020
I have two matrices A and B. I want to add up elements in matrix B for every unique element in matrix A and return C
A =[1 47 22 22
1 22 47 2
2 47 1 2]
B=[1 10 11 12
3 31 33 12
5 1 20 21]
C= [1 24
2 38
22 54
47 44] %%%%summing up values in B corresponding to unique values in matrix A, such as for matrix element 1 in A,
% sum up 1+3+20 in B to return 24 in C
I am originally dealing with a shapefile and was using inpolygon function for dealing with this, but it is taking more than 55 minutes to handle one matrix as the size of the original matrices are very big (4630*9260).
Any help is very much appreciated
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

JESUS DAVID ARIZA ROYETH am 14 Feb. 2020
m= accumarray(A(:),B(:));
d=find(m);
C=[d m(d)]
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by