Is there a way to use findgroups() so that it is based on order in the matrix instead of alphabetical?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Liam
am 13 Jul. 2023
Kommentiert: Star Strider
am 13 Jul. 2023
I am using findgroups() as an integral part of the script I'm currently working with, but the way that findgroups() outputs its groups is causing issues.
x = {'m1' 'n1' 'k1' 'k1' 'p1' 'p1' 'b1' 'b1' 'b1'}
[g,g_id] = findgroups(x)
What I would prefer is if g outputted as [1 2 3 3 4 4 5 5 5] and g_id as {'m1' 'n1' 'k1' 'p1' 'b1'}. Is there any way to do this?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 13 Jul. 2023
There doesn’t appear to be that option for findgroups. If you only have one vector, the unique function can do thaat using the 'stable' setOrder —
x = {'m1' 'n1' 'k1' 'k1' 'p1' 'p1' 'b1' 'b1' 'b1'}
[g,~,g_id] = unique(x,'stable')
.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Call Web Services from MATLAB Using HTTP 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!