How to output in Octave GNU

21 Jun, 2021
Octave is open-source, free available for many of the platforms. It is a high-level language. It comes up with a text interface along with an experimental graphical interface. It is also used for various Machine Learning algorithms for solving various numeric problems. You can say that it is similar to MATLAB but slower than MATLAB.There are multiple library functions to display an output in Octave. 
The printf() function prints the characters and returns the number of character printed, the format is a string starting with % and ends with conversion character (like c, i, f, d, etc.). 
Syntax : printf(template, variables) Parameters :  
template : string to be written on the console, it also contains format specifiers like %d, %s etc
variables : values that will replace the format specifiers
Types of Format Specifiers :  
%d : used for integers
%f : used for floating point values
%s : used for strings
Returns : number of characters printed  
Example :  
MATLAB
% using printf() without format specifiersprintf("Hello World!!\n"); x = 5; % using printf() with format specifiersprintf("Welcome, value of x is %d\n", x);
Output :  
Hello World!!
Welcome, value of x is 5
 
The fprintf() function is equivalent to the printf() function, except that the output is written to the file descriptor fid instead of stdout. 
Syntax : fprintf(fid, template, variables) Parameters :  
fid : file descriptor
template : string to be written on the console, it also contains format specifiers like %d, %s etc
variables : values that will replace the format specifiers
Types of Format Specifiers :  
%d : used for integers
%f : used for floating point values
%s : used for strings
Returns : number of characters printed  
Example :  
MATLAB
% using fprintf() without format specifiersfprintf("Hello World!!\n"); x = 5; % using fprintf() with format specifiersprintf("Welcome, value of x is %d\n", x);
Output :  
Hello World!!
Welcome, value of x is 5
 
The sprintf() function is like the printf() function, except that the output is returned as a string. 
Syntax : sprintf(template, variables) Parameters :  
template : string to be written on the console, it also contains format specifiers like %d, %s etc
variables : values that will replace the format specifiers
Types of Format Specifiers :  
%d : used for integers
%f : used for floating point values
%s : used for strings
Returns : number of characters printed  
 
MATLAB
% using sprintf() without format specifiersfprintf("Hello World!!\n"); x = 5; % using sprintf() with format specifiersprintf("Welcome, value of x is %d\n", x);
Output :  
Hello World!!
Welcome, value of x is 5
 
The disp() function is used to either display the value on the console or assign the value to a variable.  
Syntax : disp(argument) Parameters :  
argument : can either be a string or a variable
Returns : the string/value printed  
Example: 
MATLAB
% displaying the value of the consoledisp("Hello World!!"); % assigning the value to a variableoutput = disp("Welcome"); % displaying the assigned variable valuedisp(output);
Output :  
Hello World!!
Welcome
 
saurabh1990aror
Octave-GNU
Programming Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.