cols#

Purpose#

Returns the number of columns in a matrix.

Format#

n_cols = cols(x)#
Parameters:

x (NxK matrix or sparse matrix)

Returns:

n_cols (scalar) – number of columns in x.

Examples#

// Create a 100x3 matrix of uniform random numbers
x = rndu(100, 3);

// Find out how many columns are in 'x'
n_cols = cols(x);

After the code above:

n_cols = 3

Remarks#

Use getorders() to return both the number of rows and columns in one call. If x is an empty matrix, rows(x) and cols(x) both return 0.

See also

Functions rows(), colsf(), getorders(), show