formatMatrix function

Format a matrix and add index column.