O'Reilly logo

GNU Octave by Jesper Schmidt Hansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required