1
Matlab 里的 PivotTable
source link: https://zhiqiang.org/coding/pivottable-in-matlab.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Matlab 里的 PivotTable
Excel 的数据透视表是一个很好用的功能,我写了一个 Matlab 版本,在处理上和 Excel 的透视表差不多,还差一个 filter 而已。
一个简单的例子:
let inMatrix = { '2009', 'Mon', 12, 31; '2009', 'Wed', 11, 34; '2009', 'Fri', 1, 4; '2009', 'Mon', 3, 4; '2009', 'Wed', 9, 6; '2009', 'Fri', 1, 4; '2010', 'Mon', 18, 15; '2010', 'Wed', 11, 21; '2010', 'Wed', 1, 4; }; then pivottable(inMatrix, 1, 2, 3, @sum) output a cell [] 'Fri' 'Mon' 'Wed' '2009' [ 2] [ 15] [ 20] '2010' [] [ 18] [ 12] pivottable(inMatrix, [1 2], [], 3, @sum) output a cell '2009' 'Fri' [ 2] '2009' 'Mon' [15] '2009' 'Wed' [20] '2010' 'Mon' [18] '2010' 'Wed' [12] pivottable(inMatrix, [], 2, 3, @sum) output a cell 'Fri' 'Mon' 'Wed' [ 2] [ 33] [ 32]
更多帮助可在 Matlab 命令行 help pivottable。
我已经提交到了Matlab Central File Exchange,觉得好的同学们帮忙打个五颗星吧。
Q. E. D.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK