Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!50g2000hsm.googlegroups.com!not-for-mail
From:  "G.A.M." <x0Zero@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Is Matlab Help incorrect Re: inputParser  (parser is not validating serial object correctly)
Date: Tue, 25 Sep 2007 15:55:02 -0000
Organization: http://groups.google.com
Lines: 69
Message-ID: <1190735702.705426.76450@50g2000hsm.googlegroups.com>
References: <1190511764.536671.125930@y42g2000hsy.googlegroups.com>
NNTP-Posting-Host: 24.129.101.179
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Trace: posting.google.com 1190735702 5954 127.0.0.1 (25 Sep 2007 15:55:02 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 25 Sep 2007 15:55:02 +0000 (UTC)
In-Reply-To: <fd8gch$fvn$1@fred.mathworks.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: 50g2000hsm.googlegroups.com; posting-host=24.129.101.179;
Xref: news.mathworks.com comp.soft-sys.matlab:430101




>
> "G.A.M." <x0Z...@gmail.com> wrote in messagenews:1190511764.536671.125930@y42g2000hsy.googlegroups.com...
> > My error msg is:
> > Argument 'serialPort' failed validation @(sp)isa(sp,'serial').
>
> > My code is:
>
> > function status = DoSomethingWithSerialPort(serialPort, varargin)
>
> > p = inputParser;
> > p.addRequired('serialPort', @(sp)isa(sp, 'serial'));
> > p.addParamValue('test','', @ischar);
> > p.parse('serialPort', varargin{:});
> > test= p.Results.test;
> >       %etc.
>
> > After getting the error, I checked the class of the function
> > parameter, and it was as expected:
> > class(serialPort)
> > ans = serial
>
> > Then, to continue debugging, I created this anonymous function in the
> > workspace:
> > x = @(sp)isa(sp, 'serial')
>
> > I used it to check the input parameter and it was again as expected:
> > x(serialPort)
> > ans =      1
>
> > So does anyone have any idea why I get the error shown at the top?
> > Thanks.


On Sep 24, 10:08 am, "Philip Borghesani"
<philip_borghes...@mathworks.spam> wrote:
> You have the inputs to parse wrong try:
> p.parse(varargin{:});
> or
> parse(p,varargin{:})
>
> Phil

Phil-thanks for your reply.
Matlab help on input parser gives this example:

function publish_ip(script, varargin)
p = inputParser;
p.addRequired('script', @ischar);
p.addOptional(...
[snip]
p.parse(script, varargin{:});

That's the example I'm following and I have used this style in a lot
of places in my code where it has seemingly worked correctly.

What I took from the example is that required arguments need to be
named in the call to parse().

1. Is the example code I posted originally an incorrect implementation
of what is shown in Matlab help?
2. Am I misunderstanding the example?
3. Is the help example incorrect?

Here's the help section I'm viewing:
inputParser :: Functions (MATLAB Function Reference)
help/techdoc/help.jar!/ref/inputparser.html