How to know the date to which a group (findgroups) corresponds?
    조회 수: 6 (최근 30일)
  
       이전 댓글 표시
    
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
채택된 답변
  Adam Danz
    
      
 2020년 9월 6일
        
      편집: Adam Danz
    
      
 2020년 9월 6일
  
      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
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


