Printing - matrices:
For matrices, the MATLAB unwinds the matrix column by column. For illustration, consider the random 2 × 3 matrix as shown below:
>> mat = randint(2,3,[1,10])
mat =
5 9 8
4 1 10
Identifying one conversion character and then the newline character will print the elements from the matrix in one column. The initial values printed are from the initial column, then the second column, and so forth.
>> fprintf('%d\n', mat)
5
4
9
1
8
10
If three of the %d conversion characters are specified, then the fprintf will print three numbers across on each line of output, but again the matrix is unwind column by column. It again prints first the two numbers from the initial column, and then the first value from the second column, and so forth.
>> fprintf('%d %d %d\n', mat)
5 4 9
1 8 10
If the transpose of the matrix is printed, though, using the three %d conversion characters, the matrix are printed as it appears whenever created.
>> fprintf('%d %d %d\n', mat') % Note the transpose
5 9 8
4 1 10