MATLAB: Find Median of the second column when first column is Date

datemedian

I have a an Excel file of two columns, First column is date in this format (mm/dd/yy), Second column is observations (number).
I have multiple observations each day and I want to find the Median of these observations for each day separately and save it an Excel file of two columns, first is the day, second is the result (Median).
I start doing this in Excel, but I realized its going to take me forever since I have a large amount of data.
How can I do this in Matlab ?

Best Answer

In excel, you would be able to do this easily with a pivot table if only pivot tables supported calculating the median (you can get the sum, mean, standard deviation, and a few others, but not the median!).
In matlab, you'd read your excel file with readtable, then use findgroups and splitapply to Split Data into Groups and Calculate Statistics. Finally writetable back into excel.
Something like:
t = readtable('C:\somewhere\yourfile.xlsx');
[group, dates] = findgroups(t.NameOfDateColumn);
medobvservation = splitapply(@median, t.NameOfObservationColumn, group);
writetable(table(dates, medobvservation), 'C:\somewhere\newfile.xlsx');