How to evaluate mean for column
Mostra commenti meno recenti
I have a data with 5 columns: X,Y,Z,A,B, the first three columns represent coordinates, the next ones some attributes of objects.
A column has values: 0 or 1, B columns has values: 1, 1, 1, 2, 2, 3, 3, ,3 ,3 , 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, ....
I would like to evaluate the mean value of A column for every individual value in column B. Eg. Evaluate mean value from column A but only for points which in B have value 1.
Does somebody know which function should I use to do this? Thank you in advance!
Risposta accettata
Più risposte (2)
Andrei Bobrov
il 6 Mag 2015
[~,~,c] = unique(B);
out = accumarray(c(:),A(:),[],@mean);
Ahmet Cecen
il 5 Mag 2015
Below does the example you listed, change the value 1 to do the others.
mean(A(B==1))
1 Commento
Karolina
il 5 Mag 2015
Categorie
Scopri di più su Variables in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!