Added flexibility C style input and output functions
The function disp
is easy to use. However, it has limitations. For example, we can display only a single variable with disp
and it always prints a newline character after displaying the variable value
Octave has implemented most of the very flexible input and output functionality that you may know from C. If not, do not worry, we will go through the most important one here, namely the printf
function. Functions that can write and read to and from files, such as fprintf, fgets
, and fscanf
, are also supported in Octave: if you want to know more about these functions, I strongly recommend you to look in the Octave manual.
printf
printf
is an acronym for print formatted text. The general syntax is:
printf(template, ...)
Here, template is a text string and can also include text format specifiers and/or escape sequences. The ..
. indicates optional arguments. For example:
octave:42>for n=1:5 >printf("n is %d\n", n); >endfor n is 1...