Time for action - checking user inputs and outputs
1. 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 << "Argument " << n+1 << " is "; #17 if ( argv(n).is_string() ) #18 octave_stdout << "a text string "; #19 if ( argv(n).is_real_scalar() ) #20 octave_stdout << "a real scalar "; #21 if...