From octave-sources-request at bevo dot che dot wisc dot edu Thu Oct 1 22:49:12 1998 Subject: new function: is_complex From: "John W. Eaton" To: Erik de Castro Lopo Cc: octave-sources at bevo dot che dot wisc dot edu Date: Thu, 1 Oct 1998 22:47:54 -0500 (CDT) On 2-Oct-1998, Erik de Castro Lopo wrote: | I found a need for a function to tell me is a vector | or matrix had any complex components. I took the | sources for is_vector our of | | /usr/local/share/octave/2.0.13/m/general/ | | and modified it as follows. I'll leave it with John's | copyright as I really don't feel I did enough to warant | putting my name on it. | | I do hwoever think that this is probably useful enough | to place in the standard distribution. Thanks for the code. I think the following is a bit better. It will work correctly even for structures and user-defined types that may give error messages when passed to imag(), and it will also be much faster for large matrices. jwe *** src/data.cc~ Mon Apr 20 22:29:48 1998 --- src/data.cc Thu Oct 1 22:39:27 1998 *************** *** 739,744 **** --- 739,757 ---- return retval; } + DEFUN (is_complex, args, , + "is_complex (x): return nonzero if x is a complex numeric object") + { + octave_value retval; + + if (args.length () == 1) + retval = args(0).is_complex_type () ? 1.0 : 0.0; + else + print_usage ("is_struct"); + + return retval; + } + DEFUN (is_struct, args, , "is_struct (x): return nonzero if x is a structure") {