find the same values and average it out
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have the following matrix A:
A =
66 2
66 3
66 4
67 6
67 3
68 5
69 6
69 3
what I would like to do is find the values that are the same in the first column and average the values in the second column and put it into a new matrix (B).
for example: I look for "66" and average the corresponding values in the second columns (i.e. 2,3,4) and the the mean is 3. So the first entry in matrix B will be:
B =
66 3
0 Commenti
Risposte (1)
Azzi Abdelmalek
il 19 Ago 2014
A =[ 66 2
66 3
66 4
67 6
67 3
68 5
69 6
69 3]
[ii,jj,kk]=unique(A(:,1))
out=[ii accumarray(kk,A(:,2),[],@mean)]
0 Commenti
Vedere anche
Categorie
Scopri di più su Get Started with MATLAB in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!