Find Median of the second column when first column is Date
Show older comments
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 ?
4 Comments
Massimo Zanetti
on 28 Sep 2016
Post an example of your data and variables, because it is not clear.
José-Luis
on 28 Sep 2016
- Import your data to Matlab xlsread()
- Get the median using accumarray(), or whatever tickles your fancy. The documentation on accumarray is horrid, IMO, but that's a rant for another day.
Guillaume
on 28 Sep 2016
For several versions now, matlab has had readtable which is a lot more powerful than xlsread.
For slightly fewer versions, matlab has had findgroups and splitapply which are easier to use than accumarray (but more or less do the same).
José-Luis
on 28 Sep 2016
Good to know. I should try to keep up.
Accepted Answer
More Answers (1)
Andrei Bobrov
on 28 Sep 2016
if your MATLAB older than R2015b
[n,tt] = xlsread('2008 Data (find daily Median).xlsx');
[y,m,d] = datevec(n(:,1));
[a,b,c] = unique([y,m,d],'rows');
z = accumarray(c,n(:,2),[],@median);
out = [tt;cellstr(datestr(n(b,1),'mm.dd.yyyy')),num2cell(z)];
xlswrite('new_file.xlsx',out);
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!