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:
Check whether variable is defined or not

Subject: Check whether variable is defined or not

From: Priyanshu Agarwal

Date: 3 Dec, 2010 18:45:23

Message: 1 of 5

Hi,

There are quite a few is* commands in MATLAB but I couldn't find one for checking whether a variable is defined or not in MATLAB workspace. Is there any command that checks whether a variable is defined or not?

Regards,
Priyanshu

Subject: Check whether variable is defined or not

From: Bruno Luong

Date: 3 Dec, 2010 18:55:26

Message: 2 of 5

"Priyanshu Agarwal" <mail2priyanshu@gmail.com> wrote in message <idbds3$il6$1@fred.mathworks.com>...
> Hi,
>
> There are quite a few is* commands in MATLAB but I couldn't find one for checking whether a variable is defined or not in MATLAB workspace. Is there any command that checks whether a variable is defined or not?

exist(..., 'var')

Bruno

Subject: Check whether variable is defined or not

From: Sean de

Date: 3 Dec, 2010 18:56:06

Message: 3 of 5

"Priyanshu Agarwal" <mail2priyanshu@gmail.com> wrote in message <idbds3$il6$1@fred.mathworks.com>...
> Hi,
>
> There are quite a few is* commands in MATLAB but I couldn't find one for checking whether a variable is defined or not in MATLAB workspace. Is there any command that checks whether a variable is defined or not?
>
> Regards,
> Priyanshu

help exist

Subject: Check whether variable is defined or not

From: Priyanshu Agarwal

Date: 3 Dec, 2010 19:25:23

Message: 4 of 5

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <idbeeu$rgp$1@fred.mathworks.com>...
> "Priyanshu Agarwal" <mail2priyanshu@gmail.com> wrote in message <idbds3$il6$1@fred.mathworks.com>...
> > Hi,
> >
> > There are quite a few is* commands in MATLAB but I couldn't find one for checking whether a variable is defined or not in MATLAB workspace. Is there any command that checks whether a variable is defined or not?
>
> exist(..., 'var')
>
> Bruno


Thanks Bruno.

Subject: Check whether variable is defined or not

From: hoque.sheikh@gmail.com

Date: 12 Mar, 2014 05:31:42

Message: 5 of 5

On Friday, December 3, 2010 12:45:23 PM UTC-6, Priyanshu Agarwal wrote:
> Hi,
>
> There are quite a few is* commands in MATLAB but I couldn't find one for checking whether a variable is defined or not in MATLAB workspace. Is there any command that checks whether a variable is defined or not?
>
> Regards,
> Priyanshu

if exist('a','var')%a is a variable
   disp('true')
else
   disp('false')
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