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 take input from the user in Octave.
var = input( "Enter an expression : " );
fprintf( "Input is %d\n" , var);
|
Output :
Enter an expression : 2 + 3
Input is 5
Example 2 : Using the “s” attribute :
var = input( "Enter an expression : " , "s" );
fprintf( "Input is %s\n" , var);
|
Output :
Enter an expression : 2 + 3
Input is 2 + 3
yes_or_no()
The yes_or_no() function accepts only two input values, either yes or no.
Syntax : yes_or_no(“prompt”)
Parameters :
- prompt : the text prompted on the terminal
Returns : 1 if “yes”, 0 if “no”
If any other value except yes or no is entered, the prompt will reappear asking for the input.
Example :
var = yes_or_no( "Enter a value : " );
disp(var)
var = yes_or_no( "Enter a value : " );
disp(var)
|
Output:
Enter a value : (yes or no) yes
1
Enter a value : (yes or no) no
0
kbhit()
The kbhit()
function waits for any keypress, after the key is pressed, it returns that key.
Syntax : kbhit(argument)
Parameters :
- argument : if called with an argument, it does not wait for a keypress
Returns : depends on the input value
Example :
ans = a
ans =
menu()
The menu()
function is used to display a menu with a heading title and options, and wait for the user input. If the GUI is running, the menu is displayed graphically Otherwise, the title and menu options are printed on the console.
Syntax : menu(title, opt1, …)
Parameters :
- title : title of the menu window
- opt1, opt2 … : list of options in the menu window
Returns : depends on the option selected
Example :
choice = menu( "title" , "opt1" , "opt2" , "opt3" );
fprintf( "The choice is : " );
disp(choice);
|