Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Is Matlab Help incorrect Re: inputParser  (parser is not validating serial object correctly)
Date: Tue, 2 Oct 2007 14:56:18 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 91
Message-ID: <fdtm6i$kql$1@fred.mathworks.com>
References: <1190511764.536671.125930@y42g2000hsy.googlegroups.com> <1190735702.705426.76450@50g2000hsm.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1191336978 21333 172.30.248.35 (2 Oct 2007 14:56:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 2 Oct 2007 14:56:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1030060
Xref: news.mathworks.com comp.soft-sys.matlab:431016



 "G.A.M." <x0Zero@gmail.com> wrote in message
<1190735702.705426.76450@50g2000hsm.googlegroups.com>...
> 
> >
> > "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
> 
> 



I could sure use some help on this. I am continuing to
struggle with the apparent differences in the help
documentation for the inputParser vs. what actually works. I
have not solved the issue I asked about in my original post
yet. The only suggestion (to not parse the required
arguments) doesn't seem satisfactory and it doesn't agree
with the help docs. What am I missing? Thanks.