table

Methods

Method Reference: table.size

table: sz = size (tbl)
table: dim_sz = size (tbl, dim)
table: dim_sz = size (tbl, vecdim)
table: [rows, columns] = size (tbl)
table: [rows, columns, …] = size (tbl)

Return the size of a table.

For tables, the size is [number-of-rows x number-of-variables]. This is the same as [height(obj), width(obj)].

size (tbl, dim) returns the size along dimension dim; dimensions greater than 2 have size 1. dim may be a vector vecdim, in which case a row vector of the corresponding sizes is returned.

Source Code: table

Example: 1

size reports [height, width] — rows by variables. A variable that spans several columns still counts as one, so the second element matches width, not the total number of underlying columns.

 Age = [38; 43; 38; 40; 49];
 BloodPressure = [124, 93; 109, 77; 125, 83; 117, 75; 122, 80];
 T = table (Age, BloodPressure)
T =
  5x2 table

    Age    BloodPressure    
    ___    _____________    

     38        124    93    
     43        109    77    
     38        125    83    
     40        117    75    
     49        122    80
 size (T)
ans =

   5   2

Query a single dimension, or capture both at once.

 nRows = size (T, 1)
nRows = 5
 [nRows, nVars] = size (T)
nRows = 5
nVars = 2