Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!2g2000prl.googlegroups.com!not-for-mail
From: jrenfree <jrenfree@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Test the existence of a variable
Date: Wed, 4 Nov 2009 13:44:49 -0800 (PST)
Organization: http://groups.google.com
Lines: 46
Message-ID: <1c9af1f6-9e23-4106-b1d1-96ebef398be2@2g2000prl.googlegroups.com>
References: <hcssc7$3rq$1@fred.mathworks.com>
NNTP-Posting-Host: 137.110.142.152
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1257371089 13416 127.0.0.1 (4 Nov 2009 21:44:49 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 4 Nov 2009 21:44:49 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: 2g2000prl.googlegroups.com; posting-host=137.110.142.152; 
	posting-account=lVpOYAoAAAD2lyD71kM3JZW0H08VNtYu
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.4) 
	Gecko/20091016 Firefox/3.5.4 (.NET CLR 3.5.30729),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:582532


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.