Hi,,is there anyone who could suggest any way of calculating the weight of a matrix row-wise?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
nafila aytija
le 2 Juin 2016
Modifié(e) : Andrei Bobrov
le 2 Juin 2016
Example,,say I have a matrix
A=[1 0 0 1;
0 1 0 1;
1 1 1 1;
1 1 0 1]
how do I calculate that how many rows have one 1's? how many have two 2's and so on?
0 commentaires
Réponse acceptée
John BG
le 2 Juin 2016
with
h=histogram(sum(A,2),[0:5])
count=h.Values
0 0 2 1 1
you have the result in the variable count, reading:
0 rows have null '1', 0 rows have one '1', 2 rows have two '1', 1 row has three '1' and 1 row has four '1'.
the histogram field to the right, filled with [0:5] defines the histogram bin edges: 4 bins need 5 edges.
If you find this answer of any help solving your question,
please click on the thumbs-up vote link, or mark it as accepted answer
thanks in advance
John
0 commentaires
Plus de réponses (1)
Andrei Bobrov
le 2 Juin 2016
Modifié(e) : Andrei Bobrov
le 2 Juin 2016
accumarray(sum(A,2)+1,1)
0 commentaires
Voir également
Catégories
En savoir plus sur Logical 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!