How to count how many times each element appears in a vector preserving the order?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MRC
am 1 Mai 2014
Bearbeitet: Azzi Abdelmalek
am 1 Mai 2014
I have a matrix A ax1, e.g.
A=[5; 5; 5; 1; 4; 4; 3; 3; 3];
I want a vector B of dimension size(unique(A))x1 which should list how many times each element of A appears in A preserving the order of A, without using loops and the option 'stable' of the command unique. In this case
B=[3;1;2;3]
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 1 Mai 2014
Bearbeitet: Azzi Abdelmalek
am 1 Mai 2014
A=[5; 5; 5; 1; 4; 4; 3; 3; 3];
[ii,jj]=unique(A);
b=hist(A,ii)
[i1,i1]=sort(jj);
B=b(i1)'
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!