pivottable

PIVOTTABLE Groups a matrix into a pivot table, is flexible as in Excel
ダウンロード: 3.4K
更新 2011/2/27

ライセンスの表示

out = pivottable(inMatrix, pivotRow, pivotColumn, valueColumn, valueFun) group
the input matrix "inMatrix" into a pivottable similar with Excel. Anyone
who are familiar with the pivottable in Excel will not have difficulties
with this function.

How the pivottables created are shown in following examples:
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]
pivottable(inMatrix, 1, 2, [3 4], {@sum, @(x)(numel(x))})
[] 'Fri' 'Fri' 'Mon' 'Mon' 'Wed' 'Wed'
'2009' [ 2] [ 2] [ 15] [ 2] [ 20] [ 2]
'2010' [] [] [ 18] [ 1] [ 12] [ 2]

author: zhang@zhiqiang.org, http://zhiqiang.org/blog/it/pivottable-in-matlab.html
version: 2011-02-28 ver 1

引用

Zhiqiang Zhang (2024). pivottable (https://www.mathworks.com/matlabcentral/fileexchange/30547-pivottable), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2010b
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersSpreadsheets についてさらに検索
謝辞

ヒントを与えたファイル: mjeppesen/matlab-pivot-table, mat2piv.m

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.0.0.0