MATLAB: Count ID-numbers over time

elementssum

Hi there,
I have the following table:
  • PID // Datum
  • 23 //'21-12-2017'
  • 23 //'28-12-2017'
  • 25 //'10-1-2018'
  • 26 //'11-1-2018'
  • 1 //'15-1-2018'
  • 25 //'17-1-2018'
  • 10 //'17-1-2018'
  • 21 //'17-1-2018'
  • 7 //'17-1-2018'
  • 11 //'17-1-2018'
I need to determine the amount of patients over time (PID = Patient ID). So in fact a function, which gives the following table:
  • Patients // Datum
  • 1 //'21-12-2017'
  • 2 //'10-01-2018'
  • 3 //'11-01-2018'etc.
Is there anyway to accomplish this? Many thanks.

Best Answer

[Datum, ~, dateidx] = unique(T.Datum);
Patients = accumarray(dateidx(:), 1);
output = table(Datum, Patients);