14.2.5 Output Conversion for Matrices

When given a matrix value, Octave’s formatted output functions cycle through the format template until all the values in the matrix have been printed. For example:

printf ("%4.2f %10.2e %8.4g\n", hilb (3));

     -| 1.00   5.00e-01   0.3333
     -| 0.50   3.33e-01     0.25
     -| 0.33   2.50e-01      0.2

If more than one value is to be printed in a single call, the output functions do not return to the beginning of the format template when moving on from one value to the next. This can lead to confusing output if the number of elements in the matrices are not exact multiples of the number of conversions in the format template. For example:

printf ("%4.2f %10.2e %8.4g\n", [1, 2], [3, 4]);

     -| 1.00   2.00e+00        3
     -| 4.00

If this is not what you want, use a series of calls instead of just one.

© 1996–2020 John W. Eaton
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://octave.org/doc/v6.3.0/Output-Conversion-for-Matrices.html