Re: [問題]MATLAB日資料加總轉成月資料
※ 引述《Dubois (Burghardt)》之銘言:
: 有一個關於MATLAB的問題想請
: 先謝謝大家幫忙了
: 原始資料--------------------
: Year Month Day CompanyA CompanyB
: 2000 1 1 10 20
: 2000 1 2 10 30
: 2000 1 3 10 40
: 2000 2 1 15 10
: 2000 2 2 16 11
: 2000 2 3 17 12
: 2000 2 4 16 11
: 想要將每間公司每個月的值算出平均
: 欲輸出資料變成如下----------------
: Year Month CompanyA CompanyB
: 2000 1 10 30
: 2000 2 16 11
: 謝謝大家了QQQQQ
dat = [2000 * ones(7,1), [1,1,1,2,2,2,2]', [1:3, 1:4]', ...
[10, 10, 10, 15:17, 16]', [20:10:40, 10:12, 11]'];
output_dat = [accumarray(dat(:,2), dat(:,1), [], @unique), ...
unique(dat(:,2)), ...
accumarray(dat(:,2), dat(:,4), [], @mean), ...
accumarray(dat(:,2), dat(:,5), [], @mean)]
% output_dat =
% 2000 1 10 30
% 2000 2 16 11
其實可以用for,對unique(dat(:,2))跑每一行就好(攤手
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.218.152.118
※ 文章網址: https://www.ptt.cc/bbs/MATLAB/M.1460204551.A.8F8.html
※ 編輯: celestialgod (180.218.152.118), 04/09/2016 20:26:20
推
04/10 21:28, , 1F
04/10 21:28, 1F