Count occurrence of unique categories in time blocks
Mostra commenti meno recenti
Cat=categorical({'A';'B';'C';'A';'B'});
Date={'01-Jan-1000 00:00:00';'01-Jan-1000 00:00:01';'01-Jan-1000 00:01:06';'01-Jan-1000 00:02:10';'01-Jan-1000 00:02:10'};
T=table(Cat,Date)
I have a table in the above format, except that the Date column is datetime and the Cat column is categorical (not sure how to put that into code for this forum, sorry).
I want to count the number of unique occurrences of A, B, C etc within a time block of 2min, starting from a certain time.
eg. Starting at 00:00:00 output should be: 0-1min A=1, B=1, C=1 and 2-3min A=1, B=1 ..whereas starting at 00:02:05 output should be: 0-1min B=1, C=1
I know I can use C=unique(T.Cat) to list the unique categories. I can also use:
TimeStep = datetime('1-Jan-1000 00:00:00') + minutes(0:29)'
[~,bin] = ismember(dateshift(T.Date,'start','minute'),TimeStep)
CountWindow = histcounts(bin,1:31)'
[CountWindowT]=table(TimeStep,CountWindow)
...to get a table of the TOTAL occurrences for the first half hour, split by minute.
How do I combine these to get an output that is split by 2min, and also the number of each unique category within the 2min blocks rather than the total count?
Risposte (1)
UQFG
il 27 Ott 2017
0 voti
Categorie
Scopri di più su Simulink in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!