Checking the exitence of a variable in Workspace from within a Function

  • Follow


Hi
I am trying  check whether a certain variable exists in the workspace 
from within a function. If the variable exists, the function will read it from workspace , else use a default value (if it is absent in the workspace).

I have tried  
   evalin('base',exist('var_name','var));
  evalin('base',any(strcmp(who,'Var_name')));

But in both cases, I get the error  'unknown command option'. Looks like evalin cannot use exist or strcmp as an option.
Would really appreciate if anyone has any insights.
Thanks
0
Reply Dweep 1/20/2011 7:29:05 PM

On 20/01/11 1:29 PM, Dweep wrote:

> I am trying check whether a certain variable exists in the workspace
> from within a function. If the variable exists, the function will read
> it from workspace , else use a default value (if it is absent in the
> workspace).
>
> I have tried evalin('base',exist('var_name','var));
> evalin('base',any(strcmp(who,'Var_name')));
>
> But in both cases, I get the error 'unknown command option'. Looks like
> evalin cannot use exist or strcmp as an option.
> Would really appreciate if anyone has any insights.

evalin('base','exist(''var_name'',''var'')');
1
Reply Think 1/20/2011 7:33:40 PM


"Think blue, count two." <roberson@hushmail.com> wrote in message <o60_o.3402$GP4.2318@newsfe02.iad>...
> On 20/01/11 1:29 PM, Dweep wrote:
> 
> > I am trying check whether a certain variable exists in the workspace
> > from within a function. If the variable exists, the function will read
> > it from workspace , else use a default value (if it is absent in the
> > workspace).
> >
> > I have tried evalin('base',exist('var_name','var));
> > evalin('base',any(strcmp(who,'Var_name')));
> >
> > But in both cases, I get the error 'unknown command option'. Looks like
> > evalin cannot use exist or strcmp as an option.
> > Would really appreciate if anyone has any insights.
> 
> evalin('base','exist(''var_name'',''var'')');

@Think blue, coubt two
Works perfectly. Both 'strcmp' and 'exist' work as valid options with evalin  once they are  enclosed within quotes--I guess this is the general syntax.
Really appreciate your prompt response.
Thanks a lot
0
Reply Dweep 1/20/2011 7:55:20 PM

2 Replies
536 Views

(page loaded in 0.048 seconds)

Similiar Articles:













7/26/2012 4:10:34 AM


Reply: