From: maxroucool mvjz on
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!
+++
From: Steven Lord on

"maxroucool mvjz" <maxroucool(a)yahoo.fr> wrote in message
news:hcssc7$3rq$1(a)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(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: jrenfree on
On Nov 4, 1:40 pm, "maxroucool mvjz" <maxrouc...(a)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.
From: maxroucool mvjz on
jrenfree <jrenfree(a)gmail.com> wrote in message <1c9af1f6-9e23-4106-b1d1-96ebef398be2(a)2g2000prl.googlegroups.com>...
> On Nov 4, 1:40?pm, "maxroucool mvjz" <maxrouc...(a)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!