Count occurrences of dates in an excel file

2 ビュー (過去 30 日間)
Zekeftw
Zekeftw 2016 年 8 月 23 日
編集済み: Andrei Bobrov 2016 年 8 月 23 日
Hi,
The attached excel file contains a list of dates. I need help counting the number of occurrences for each date then sum them for each week. Where the week is counted from Sun - Sat.
For example, for the week of 5/1/15 John placed 21 orders.
Thanks

回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2016 年 8 月 23 日
編集済み: Andrei Bobrov 2016 年 8 月 23 日
[~,~,dc] = xlsread('Orders.xlsx'); % T = readtable('Orders.xlsx');
z = dc(2:end,:); % z = table2cell(T);
t = cellfun(@ischar,z); % t = ~cellfun(@isempty,z);
nd = weekday(datenum(z(t),'dd.mm.yy'));
ds = datenum(z(t),'dd.mm.yy');
ddf = diff([nd ds]);
lo = [true;ddf(:,1) < 0 | abs(ddf(:,2)) > 7];
i0 = double(t);
i0(t) = lo;
i1 = cumsum(i0).*t + 1;
i2 = ones(size(i1,1),1) * (1:3);
out = accumarray([i1(:),i2(:)],1);
out = out(2:end,:);

KSSV
KSSV 2016 年 8 月 23 日
[num,txt,raw] = xlsread('Orders.xlsx') ;
dates = txt(:,1) ;
d = {'30-06-2016'} ;
% d = {'05-01-2015'} ;
idx = strcmp(dates,d) ;
count = length(find(idx==1));
  2 件のコメント
Zekeftw
Zekeftw 2016 年 8 月 23 日
Hi Dr. Siva Srinivas Kolukula,
Thanks for your response.
Looks like I stated my original post wrong. Your code seems to compare the dates to the the date stored in d. I actually need to count all that fall between 05-01-2016 and 05-07-2016, etc
I will use your code as a starting point.
Peter Perkins
Peter Perkins 2016 年 8 月 23 日
Your question is not quite clear to me, but you may find that converting your dates to datetime and using the week function is the way to go. Hope this helps.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by