Mean of classified data
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a matrix X where each row represents an observation. For example:
X =
1 3
2 5
5 7
and a vector column classes that represents, for each observation in X, which class it belongs to, for example
classes=
1
2
1
That means observation (1,3) and (5,7) are classified as 1 and observation (2,5) is classified as 2.
I'm looking for a efficiently method to calculate the mean of each class, so in this example, I get (3,5) mean for class 1 and (2,5) mean for class 2.
0 commentaires
Réponses (1)
Mann Baidi
le 7 Déc 2023
Hi Juanjo,
I understand you would like to perform “mean” operations on a classified 2D array.
For this you can use the “accumarray” function in MATLAB to perform arithmetic operations on classified arrays.
You can resolve your query using “accumarray” as follows:
X=[1 3;2 5; 5 7;10 15;64 67];
classes=[1 3 1 2 2]';
res=[accumarray(classes,X(:,1),[],@mean) accumarray(classes,X(:,2),[],@mean)]
You can refer to the “accumarray” documentation using the following link.
Hope this will help!
0 commentaires
Voir également
Catégories
En savoir plus sur Classification dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!