필터 지우기
필터 지우기

Find Median of the second column when first column is Date

조회 수: 1 (최근 30일)
Rawan Aloula
Rawan Aloula 2016년 9월 28일
댓글: Rawan Aloula 2016년 10월 2일
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
Guillaume
Guillaume 2016년 9월 28일
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
José-Luis 2016년 9월 28일
Good to know. I should try to keep up.

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2016년 9월 28일
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');

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 9월 28일
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);

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by