The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Using InputParse for boolean field
Replies: 3   Last Post: Apr 23, 2012 6:36 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 7
Registered: 8/27/10
Using InputParse for boolean field
Posted: Aug 27, 2010 11:06 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I am trying to add a flag called "debug" as an optional input parameter
to the function. The test function is listed below:

function untitled(a, varargin)
p = inputParser;
p.addRequired('a', @isnumeric);
p.addOptional('debug', 0, @(x)strcmpi(x, 'debug'));
p.parse(a, varargin{:})

If i type

>> untitled(3)

a: 3
debug: 0

If i type

>> untitled(3, 'debug')

a: 3
debug: 'debug'

I want Matlab to place 1 in the debug field, i.e.

>> untitled(3, 'debug')

a: 3
debug: 1

Is it possible? Do I need to play with the anonymous function handle?
FYI, matlab doc says that if the Boolean output is true, then MATLAB
accepts the input value. I want to work around this.

Thank you.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.