How to know the date to which a group (findgroups) corresponds?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello!
I have a timetable (TT) where one column is a Date (dd/mm/yyyy format) and another is an Hour, I applied the following code to classify them by groups:
groups_TT = findgroups(TT.Date, TT.Hour);
This gives me a unique number for each day and hour. My question is, how can I get an identifier from this number that tells me the Date it corresponds to? The unique number is not as useful for me to perform my analysis. I need to know the date that this number corresponds to.
I attach a small example. Here my code will give me a unique identifier (from 1 to 6) and I would like to create an additional column that tells me what date each one corresponds to (if possible another table with two columns: unique id and date)
Thanks in advance!
Angela
Réponse acceptée
Adam Danz
le 6 Sep 2020
Modifié(e) : Adam Danz
le 6 Sep 2020
findgroups()
Use the 2nd output [G,ID] = findgroups(A)
G(i) belongs to ID(G(i),:). For example,
A = ["D" "B" "B" "A" "D" "D" "D"];
[G,ID] = findgroups(A)
% G =
% 3 2 2 1 3 3 3
% ID =
% 1×3 string array
% "A" "B" "D"
So, G(1) shows that A(1) is in group #3. Group #3 is ID(3) or ID(G(1)) which is "D".
To find all samples in your data that belong to a specific group,
isGroupMember = G==find(ID=="D"); % or strcmp(ID,"D")
% or, G==3
isGroupMember is a logical vector the same size as A and contains 1s (True) where A=="D".
unique()
% ID =
% 1×3 string array
% "A" "B" "D"
% G =
% 3
% 2
% 2
% 1
% 3
% 3
% 3
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Tables 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!