How to calculate repetition of an unknown number present in 2nd column of a 150*2 matrix?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Binayak Gouda
il 20 Mag 2016
Commentato: Star Strider
il 21 Mag 2016
I've a matrix a=[1,1;2,1;3,1;4,4;5,4] . Actually numbers in the 2nd column are not known in a general case. So, how can i count how many numbers have a particular number (say 1,4) in their corresponding 2nd column.
1 Commento
Risposta accettata
Star Strider
il 20 Mag 2016
Use the unique and accumarray functions:
a=[1,1;2,1;3,1;4,4;5,4];
[a2,ia,ic] = unique(a(:,2));
ah = accumarray(ic, 1);
Result = [a2, ah]
Result =
1 3
4 2
So in the second column, there are 3 ‘1’ values and 2 ‘4’ values.
This could be easily changed if you wanted unique row pairs.
2 Commenti
Più risposte (1)
Alessandro Masullo
il 20 Mag 2016
You can use the function hist (or histc) on the second column of your matrix.
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrix Indexing 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!