<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265014</link>
    <title>MATLAB Central Newsreader - Test the existence of a variable</title>
    <description>Feed for thread: Test the existence of a variable</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>Wed, 04 Nov 2009 21:40:23 -0500</pubDate>
      <title>Test the existence of a variable</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265014#692197</link>
      <author>maxroucool mvjz</author>
      <description>Hi all,&lt;br&gt;
&lt;br&gt;
I have a really basic problem, but I don't find any solution...&lt;br&gt;
I am doing a function in which you can put 2 arguments 'files' and 'options', but 'options' is not compulsory.&lt;br&gt;
So I want to test its existence, and if the user didn't set any options, so I have to give the default value to 'options'.&lt;br&gt;
Here is my code:&lt;br&gt;
&lt;br&gt;
[code]&lt;br&gt;
if exist(options,'var') &amp;&amp; strcmp(options.denoised.state, 1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ~isfield(options.denoised,'threshold')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;options.denoised.threshold = 'heursure';&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ~isfield(options.denoised,'wname')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;options.denoised.wname = 'sym8';&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ~isfield(options.denoised,'level')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;options.denoised.level = 5;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
else&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;options.denoised.state = 0;                 % Bool: Denoise signal or not?&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;options.denoised.threshold = 'heursure';    % Can be: rigrsure, heursure, sqtwolog, minimaxi&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;options.denoised.wname = 'sym8';            % Many different names: see wfilters()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;options.denoised.level = 5;                 % Level&lt;br&gt;
end&lt;br&gt;
[/code]&lt;br&gt;
&lt;br&gt;
But when I run it, Matlab says me: &quot;??? Undefined function or variable 'options'.&quot; !!!&lt;br&gt;
That's wired, isn't it ?!?&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Thank you for you help!&lt;br&gt;
+++</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 21:45:08 -0500</pubDate>
      <title>Re: Test the existence of a variable</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265014#692200</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;maxroucool mvjz&quot; &amp;lt;maxroucool@yahoo.fr&amp;gt; wrote in message &lt;br&gt;
news:hcssc7$3rq$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Hi all,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have a really basic problem, but I don't find any solution...&lt;br&gt;
&amp;gt; I am doing a function in which you can put 2 arguments 'files' and &lt;br&gt;
&amp;gt; 'options', but 'options' is not compulsory.&lt;br&gt;
&amp;gt; So I want to test its existence, and if the user didn't set any options, &lt;br&gt;
&amp;gt; so I have to give the default value to 'options'.&lt;br&gt;
&amp;gt; Here is my code:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; [code]&lt;br&gt;
&amp;gt; if exist(options,'var') &amp;&amp; strcmp(options.denoised.state, 1)&lt;br&gt;
&lt;br&gt;
You want the EXIST call to use the _name_ of the variable to be tested, not &lt;br&gt;
the variable itself.&lt;br&gt;
&lt;br&gt;
if exist('options', 'var') ...&lt;br&gt;
&lt;br&gt;
You may also want to throw in an ISSTRUCT and/or ISFIELD call into the mix &lt;br&gt;
to make sure that options is a struct array with a field denoised that is &lt;br&gt;
itself a struct that has a field state.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com&lt;br&gt;
comp.soft-sys.matlab (CSSM) FAQ: &lt;a href=&quot;http://matlabwiki.mathworks.com/MATLAB_FAQ&quot;&gt;http://matlabwiki.mathworks.com/MATLAB_FAQ&lt;/a&gt; </description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 21:44:49 -0500</pubDate>
      <title>Re: Test the existence of a variable</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265014#692201</link>
      <author>jrenfree</author>
      <description>On Nov 4, 1:40&#160;pm, &quot;maxroucool mvjz&quot; &amp;lt;maxrouc...@yahoo.fr&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hi all,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have a really basic problem, but I don't find any solution...&lt;br&gt;
&amp;gt; I am doing a function in which you can put 2 arguments 'files' and 'options', but 'options' is not compulsory.&lt;br&gt;
&amp;gt; So I want to test its existence, and if the user didn't set any options, so I have to give the default value to 'options'.&lt;br&gt;
&amp;gt; Here is my code:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; [code]&lt;br&gt;
&amp;gt; if exist(options,'var') &amp;&amp; strcmp(options.denoised.state, 1)&lt;br&gt;
&amp;gt; &#160; &#160; if ~isfield(options.denoised,'threshold')&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; options.denoised.threshold = 'heursure';&lt;br&gt;
&amp;gt; &#160; &#160; end&lt;br&gt;
&amp;gt; &#160; &#160; if ~isfield(options.denoised,'wname')&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; options.denoised.wname = 'sym8';&lt;br&gt;
&amp;gt; &#160; &#160; end&lt;br&gt;
&amp;gt; &#160; &#160; if ~isfield(options.denoised,'level')&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; options.denoised.level = 5;&lt;br&gt;
&amp;gt; &#160; &#160; end&lt;br&gt;
&amp;gt; else&lt;br&gt;
&amp;gt; &#160; &#160; options.denoised.state = 0; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; % Bool: Denoise signal or not?&lt;br&gt;
&amp;gt; &#160; &#160; options.denoised.threshold = 'heursure'; &#160; &#160;% Can be: rigrsure, heursure, sqtwolog, minimaxi&lt;br&gt;
&amp;gt; &#160; &#160; options.denoised.wname = 'sym8'; &#160; &#160; &#160; &#160; &#160; &#160;% Many different names: see wfilters()&lt;br&gt;
&amp;gt; &#160; &#160; options.denoised.level = 5; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; % Level&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; [/code]&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; But when I run it, Matlab says me: &quot;??? Undefined function or variable 'options'.&quot; !!!&lt;br&gt;
&amp;gt; That's wired, isn't it ?!?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thank you for you help!&lt;br&gt;
&amp;gt; +++&lt;br&gt;
&lt;br&gt;
You need to put ''s around the variable you're looking for.  So it&lt;br&gt;
should be:&lt;br&gt;
&lt;br&gt;
if exist('options', 'var') ...&lt;br&gt;
&lt;br&gt;
Look at help exist for more info.</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 22:33:03 -0500</pubDate>
      <title>Re: Test the existence of a variable</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265014#692214</link>
      <author>maxroucool mvjz</author>
      <description>jrenfree &amp;lt;jrenfree@gmail.com&amp;gt; wrote in message &amp;lt;1c9af1f6-9e23-4106-b1d1-96ebef398be2@2g2000prl.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On Nov 4, 1:40?pm, &quot;maxroucool mvjz&quot; &amp;lt;maxrouc...@yahoo.fr&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; Hi all,&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I have a really basic problem, but I don't find any solution...&lt;br&gt;
&amp;gt; &amp;gt; I am doing a function in which you can put 2 arguments 'files' and 'options', but 'options' is not compulsory.&lt;br&gt;
&amp;gt; &amp;gt; So I want to test its existence, and if the user didn't set any options, so I have to give the default value to 'options'.&lt;br&gt;
&amp;gt; &amp;gt; Here is my code:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; [code]&lt;br&gt;
&amp;gt; &amp;gt; if exist(options,'var') &amp;&amp; strcmp(options.denoised.state, 1)&lt;br&gt;
&amp;gt; &amp;gt; ? ? if ~isfield(options.denoised,'threshold')&lt;br&gt;
&amp;gt; &amp;gt; ? ? ? ? options.denoised.threshold = 'heursure';&lt;br&gt;
&amp;gt; &amp;gt; ? ? end&lt;br&gt;
&amp;gt; &amp;gt; ? ? if ~isfield(options.denoised,'wname')&lt;br&gt;
&amp;gt; &amp;gt; ? ? ? ? options.denoised.wname = 'sym8';&lt;br&gt;
&amp;gt; &amp;gt; ? ? end&lt;br&gt;
&amp;gt; &amp;gt; ? ? if ~isfield(options.denoised,'level')&lt;br&gt;
&amp;gt; &amp;gt; ? ? ? ? options.denoised.level = 5;&lt;br&gt;
&amp;gt; &amp;gt; ? ? end&lt;br&gt;
&amp;gt; &amp;gt; else&lt;br&gt;
&amp;gt; &amp;gt; ? ? options.denoised.state = 0; ? ? ? ? ? ? ? ? % Bool: Denoise signal or not?&lt;br&gt;
&amp;gt; &amp;gt; ? ? options.denoised.threshold = 'heursure'; ? ?% Can be: rigrsure, heursure, sqtwolog, minimaxi&lt;br&gt;
&amp;gt; &amp;gt; ? ? options.denoised.wname = 'sym8'; ? ? ? ? ? ?% Many different names: see wfilters()&lt;br&gt;
&amp;gt; &amp;gt; ? ? options.denoised.level = 5; ? ? ? ? ? ? ? ? % Level&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; [/code]&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; But when I run it, Matlab says me: &quot;??? Undefined function or variable 'options'.&quot; !!!&lt;br&gt;
&amp;gt; &amp;gt; That's wired, isn't it ?!?&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Thank you for you help!&lt;br&gt;
&amp;gt; &amp;gt; +++&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You need to put ''s around the variable you're looking for.  So it&lt;br&gt;
&amp;gt; should be:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; if exist('options', 'var') ...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Look at help exist for more info.&lt;br&gt;
&lt;br&gt;
OK thank to both of you for your rapidity and your efficiency!!&lt;br&gt;
&lt;br&gt;
Bye!</description>
    </item>
  </channel>
</rss>

