help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with inputParser and anonymous functions for validators


From: Ben Abbott
Subject: Re: Problem with inputParser and anonymous functions for validators
Date: Fri, 21 Sep 2012 14:33:16 -0400

On Sep 21, 2012, at 2:12 PM, Jose wrote:

> Hello.
> 
> I am trying to use inputParser and anonymous functions for validators. I get 
> errors, as follows.
> 
> octave:2> p = inputParser;
> octave:3> val = @(x) ischar(x);
> octave:4> val('hello')
> ans =  1
> octave:5> p = addRequired (p,"pack", @val);
> error: @val: no function and no method found
> error: evaluating argument list element number 3
> octave:5> p = addRequired (p,"pack", @ischar);
> 
> 
> Any hints?
> I am using octave 3.6.2 and general package 1.3.2
> 
> BR
> Jose

@char is a function handle for the function char(). "val" is the function 
handle @(x)ischar(x).  @val is invalid syntax.

What you need to do is either 

(1) addRequired (p, "pack", val)

or

(2) addRequired (p, "pack", @(x)ischar(x))

or 

(3) addRequired (p, "pack", @ischar)

Ben




reply via email to

[Prev in Thread] Current Thread [Next in Thread]