I have a data set of sales at different dates in MATLAB.
I want to find the average sales on day of the cycle, day two of the cyle etc.. (cycle is one week so seven days) of each product.
My data set is csv file with the date in yyyy-mm-dd format and sales in numerical.
To plot my data I have:
f = fopen('salesdata.csv');
data = textscan(f, '%s %f %f %f %f %f ', 'Delimiter', ',', 'HeaderLines', 1);
fclose(f);
data{1} = datenum(data{1});
Date = data{1};
Product3 = data{4};
Product4 = data{5};
Product5 = data{6};
plot(Date, Product 4, 'k')
Please can someone give me any advice!

댓글 수: 1

dpb
dpb 2016년 5월 16일
Five or seven (or other) day week and do you have complete weeks' worth of data or missing or incomplete weeks?
There's a simple way if complete; simply reshape by number of days and average over the N columns.

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

답변 (1개)

Jos (10584)
Jos (10584) 2016년 5월 16일

1 개 추천

First, do not name your products like this. Use the cell array directly with indexing, or convert to a struct.
A solution to get the averages per week day. First retrieve, the days in the cycle using unique, and then apply accumarray
Days = weekday(data{1}) % some conversion from dates to weekdays
[UniqueDays,~,idx] = unique(Days)
% convert to a struct array for coding convenience
S(1).values = Data{3} ;
S(1).name = 'Product X' ;
% ...
for k = 1:numel(S)
S(k).CycleAvg = accumarray(idx, S(k).values,[],@mean,NaN) ;
end

댓글 수: 1

Jos (10584)
Jos (10584) 2016년 5월 16일
untested btw, but you should be able to get the point.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2016년 5월 16일

댓글:

2016년 5월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by