Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Test the existence of a variable
Date: Wed, 4 Nov 2009 16:45:08 -0500
Organization: The MathWorks, Inc.
Lines: 30
Message-ID: <hcssjc$hnf$1@fred.mathworks.com>
References: <hcssc7$3rq$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1257371052 18159 172.31.44.65 (4 Nov 2009 21:44:12 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Nov 2009 21:44:12 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:582531



"maxroucool mvjz" <maxroucool@yahoo.fr> wrote in message 
news:hcssc7$3rq$1@fred.mathworks.com...
> Hi all,
>
> I have a really basic problem, but I don't find any solution...
> I am doing a function in which you can put 2 arguments 'files' and 
> 'options', but 'options' is not compulsory.
> 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'.
> Here is my code:
>
> [code]
> if exist(options,'var') && strcmp(options.denoised.state, 1)

You want the EXIST call to use the _name_ of the variable to be tested, not 
the variable itself.

if exist('options', 'var') ...

You may also want to throw in an ISSTRUCT and/or ISFIELD call into the mix 
to make sure that options is a struct array with a field denoised that is 
itself a struct that has a field state.

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ