Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to check whether "variable_A" is exist in workspace?

Subject: How to check whether "variable_A" is exist in workspace?

From: Marco Wu

Date: 19 Sep, 2011 19:03:29

Message: 1 of 4

Dear all,

I want to create a varialble_A if it has not been created yet. I do not want to overwrite the variable_A if it is existed. What function that I can use to check the existing of variable_A in workspace?

Thanks

Subject: How to check whether "variable_A" is exist in workspace?

From: Bruno Luong

Date: 19 Sep, 2011 19:11:26

Message: 2 of 4

"Marco Wu" wrote in message <j583m0$1qk$1@newscl01ah.mathworks.com>...
> What function that I can use to check the existing of variable_A in workspace?
>

The most obvious: EXIST

Bruno

Subject: How to check whether "variable_A" is exist in workspace?

From: ScottB

Date: 19 Sep, 2011 19:14:28

Message: 3 of 4

"Marco Wu" wrote in message <j583m0$1qk$1@newscl01ah.mathworks.com>...
> Dear all,
>
> I want to create a varialble_A if it has not been created yet. I do not want to overwrite the variable_A if it is existed. What function that I can use to check the existing of variable_A in workspace?
>
> Thanks

Marco,

Take a look at the command "exist".

hth,
ScottB

Subject: How to check whether "variable_A" is exist in workspace?

From: Matt J

Date: 19 Sep, 2011 19:26:26

Message: 4 of 4

"Marco Wu" wrote in message <j583m0$1qk$1@newscl01ah.mathworks.com>...
> Dear all,
>
> I want to create a varialble_A if it has not been created yet. I do not want to overwrite the variable_A if it is existed. What function that I can use to check the existing of variable_A in workspace?
=======

A lazy way:

try,
 A;
catch,
 A=whatever;
end

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us