If you call 'length(M)', you get the number of rows, but as far as I can see there is no easy way to get the number of columns in a matrix.
I have been using 'length(list_matrix_entries(row(M,1)))', but this is long and probably inefficient (?).
Can i suggest two new functions:
rows(M) - A synonym for length(M)
cols(M) - Returns the number of columns in a matrix