Arrange the array to give the added output in other array
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
SUBHO MITRA
il 22 Apr 2022
Commentato: SUBHO MITRA
il 22 Apr 2022
In the following array B contains the individual results for the elements in A
Let's say,
A=[2 1 4 2 8 4 1 7 2].';
B=[1 2 3 4 5 6 7 8 9].';
Now, I want A in such a way that It only contains the the unique elements in it, like final A should be:
A=[1 2 4 7 8];
And in final B it contains the total addition of the each individual values of elements in A, so final B will look like:
B=[9 14 9 5 8];
I am looking for a simple code to execute this, it is urgent
0 Commenti
Risposta accettata
Stephen23
il 22 Apr 2022
A = [2;1;4;2;8;4;1;7;2];
B = [1;2;3;4;5;6;7;8;9];
[X,Y,Z] = unique(A);
N = accumarray(Z,B)
display(X)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!