<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/250456</link>
    <title>MATLAB Central Newsreader - Syntax checking</title>
    <description>Feed for thread: Syntax checking</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sun, 03 May 2009 18:32:01 -0400</pubDate>
      <title>Syntax checking</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/250456#647010</link>
      <author>Adam </author>
      <description>Hi all,&lt;br&gt;
&lt;br&gt;
I am programming a toolbox and I have the following question:&lt;br&gt;
&lt;br&gt;
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...&lt;br&gt;
&lt;br&gt;
If matlab had this, then one could easily put all syntax checking up front, and also expect to get nice error messages.&lt;br&gt;
&lt;br&gt;
Thank you!&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;Adam</description>
    </item>
    <item>
      <pubDate>Sun, 03 May 2009 20:23:02 -0400</pubDate>
      <title>Re: Syntax checking</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/250456#647019</link>
      <author>Matt Fig</author>
      <description>The closest function that I know of is nargchk.  But I don't think it fulfills all your requirements.  I always write my own input checking which goes at the head of the function, it is not to hard to do this.</description>
    </item>
    <item>
      <pubDate>Sun, 03 May 2009 20:49:01 -0400</pubDate>
      <title>Re: Syntax checking</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/250456#647024</link>
      <author>Jiro Doke</author>
      <description>&quot;Adam &quot; &amp;lt;king@cs.fairfield.edu&amp;gt; wrote in message &amp;lt;gtknv1$mr4$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi all,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am programming a toolbox and I have the following question:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If matlab had this, then one could easily put all syntax checking up front, and also expect to get nice error messages.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you!&lt;br&gt;
&amp;gt;    Adam&lt;br&gt;
&lt;br&gt;
Adam,&lt;br&gt;
&lt;br&gt;
If you're using R2007a or newer, you can use the inputParser class:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/bresuxt-1.html#bresuxt-11&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/bresuxt-1.html#bresuxt-11&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
(note that this is from the current documentation)&lt;br&gt;
&lt;br&gt;
NARGCHK will check the number of arguments:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/ref/nargchk.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/ref/nargchk.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Also, VALIDATEATTRIBUTES and VALIDATESTRING may be useful (R2007b or newer):&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/ref/validateattributes.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/ref/validateattributes.html&lt;/a&gt;&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/ref/validatestring.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/ref/validatestring.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Hope this helps.&lt;br&gt;
&lt;br&gt;
jiro</description>
    </item>
    <item>
      <pubDate>Sun, 03 May 2009 21:28:01 -0400</pubDate>
      <title>Re: Syntax checking</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/250456#647029</link>
      <author>Adam </author>
      <description>Thank you both. This really helps a lot.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;-- Adam</description>
    </item>
  </channel>
</rss>

