table.width
table: W = width (tbl)
Number of variables in table.
W = width (tbl) returns the number of variables in the
table tbl as a scalar. It is the equivalent of
size (tbl, 2).
Note that this is the number of table variables, not the total number of columns. A single variable may itself contain several columns (for example, a matrix-valued variable), but it still counts as one towards the table width.
For a table with no variables, width returns 0.
Source Code: table
width counts variables, not the underlying columns. BloodPressure is a single variable spanning two columns, so the width is 2, not 3.
Age = [38; 43; 38; 40; 49]; Smoker = logical ([1; 0; 1; 0; 1]); BloodPressure = [124, 93; 109, 77; 125, 83; 117, 75; 122, 80]; T = table (Age, Smoker, BloodPressure)
T =
5x3 table
Age Smoker BloodPressure
___ ______ _____________
38 true 124 93
43 false 109 77
38 true 125 83
40 false 117 75
49 true 122 80
width (T)
ans = 3
Splitting the multi-column variable into scalar columns raises the width.
width (splitvars (T))
ans = 4