Time for action – checking user inputs and outputs
- Code Listing 8.2 shows an example of a function called
args
. This function takes any number of inputs, checks what type they are, and writes this to the Octave command prompt. It returns a sequence of numbers going from 1 to the number of input arguments:Code Listing 8.2 #include <octave/oct.h> #1 #2 #define HELP_TEXT "Usage:[out1,out2,...]=args(in1,in2,...)" #3 #4 DEFUN_DLD(args, argv, nargout, HELP_TEXT){ #5 octave_value_list retval; #6 #7 int nargs = argv.length(); #8 octave_stdout<<"You've entered "<< nargs << " argument(s)\n";#9 #10 if ( nargout > nargs ){ #11 error("Number of output variables is too large"); #12 return retval; #13 } #14 #15 for ( int n=0; n<nargs; n++ ){ #16 octave_stdout ...
Get GNU Octave now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.