pivottable
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
Zitieren als
Zhiqiang Zhang (2025). pivottable (https://de.mathworks.com/matlabcentral/fileexchange/30547-pivottable), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Plattform-Kompatibilität
Windows macOS LinuxKategorien
Tags
Quellenangaben
Inspiriert: 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!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
| Version | Veröffentlicht | Versionshinweise | |
|---|---|---|---|
| 1.0.0.0 |
