Path: news.mathworks.com!not-for-mail
From: "maxroucool mvjz" <maxroucool@yahoo.fr>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Test the existence of a variable
Date: Wed, 4 Nov 2009 22:33:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 44
Message-ID: <hcsvev$gch$1@fred.mathworks.com>
References: <hcssc7$3rq$1@fred.mathworks.com> <1c9af1f6-9e23-4106-b1d1-96ebef398be2@2g2000prl.googlegroups.com>
Reply-To: "maxroucool mvjz" <maxroucool@yahoo.fr>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257373983 16785 172.30.248.38 (4 Nov 2009 22:33:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Nov 2009 22:33:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2077384
Xref: news.mathworks.com comp.soft-sys.matlab:582545


jrenfree <jrenfree@gmail.com> wrote in message <1c9af1f6-9e23-4106-b1d1-96ebef398be2@2g2000prl.googlegroups.com>...
> On Nov 4, 1:40?pm, "maxroucool mvjz" <maxrouc...@yahoo.fr> wrote:
> > 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)
> > ? ? if ~isfield(options.denoised,'threshold')
> > ? ? ? ? options.denoised.threshold = 'heursure';
> > ? ? end
> > ? ? if ~isfield(options.denoised,'wname')
> > ? ? ? ? options.denoised.wname = 'sym8';
> > ? ? end
> > ? ? if ~isfield(options.denoised,'level')
> > ? ? ? ? options.denoised.level = 5;
> > ? ? end
> > else
> > ? ? options.denoised.state = 0; ? ? ? ? ? ? ? ? % Bool: Denoise signal or not?
> > ? ? options.denoised.threshold = 'heursure'; ? ?% Can be: rigrsure, heursure, sqtwolog, minimaxi
> > ? ? options.denoised.wname = 'sym8'; ? ? ? ? ? ?% Many different names: see wfilters()
> > ? ? options.denoised.level = 5; ? ? ? ? ? ? ? ? % Level
> > end
> > [/code]
> >
> > But when I run it, Matlab says me: "??? Undefined function or variable 'options'." !!!
> > That's wired, isn't it ?!?
> >
> > Thank you for you help!
> > +++
> 
> You need to put ''s around the variable you're looking for.  So it
> should be:
> 
> if exist('options', 'var') ...
> 
> Look at help exist for more info.

OK thank to both of you for your rapidity and your efficiency!!

Bye!