Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Syntax checking
Date: Sun, 3 May 2009 20:49:01 +0000 (UTC)
Organization: The MathWorks Inc
Lines: 33
Message-ID: <gtkvvt$1jb$1@fred.mathworks.com>
References: <gtknv1$mr4$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1241383741 1643 172.30.248.37 (3 May 2009 20:49:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 3 May 2009 20:49:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869871
Xref: news.mathworks.com comp.soft-sys.matlab:537074


"Adam " <king@cs.fairfield.edu> wrote in message <gtknv1$mr4$1@fred.mathworks.com>...
> Hi all,
> 
> I am programming a toolbox and I have the following question:
> 
> Does matlab have any built in functions to confirm the correct syntax for a call to ones own function. For example, it would be nice to specify that the function needs either an array followed by a cell array, or, just the string 'all', or two strings where the first one is not 'all', etc...
> 
> If matlab had this, then one could easily put all syntax checking up front, and also expect to get nice error messages.
> 
> Thank you!
>    Adam

Adam,

If you're using R2007a or newer, you can use the inputParser class:

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/bresuxt-1.html#bresuxt-11

(note that this is from the current documentation)

NARGCHK will check the number of arguments:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/nargchk.html

Also, VALIDATEATTRIBUTES and VALIDATESTRING may be useful (R2007b or newer):

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/validateattributes.html
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/validatestring.html


Hope this helps.

jiro