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:
Variable names

Subject: Variable names

From: M K

Date: 12 May, 2009 13:44:02

Message: 1 of 3

An array 'x' is dependent on a value of 'A'. I would like the name of 'x' be
dependent on the value of 'A'. for example
if A =1 , I want 'x' to be named 'x1' and
if A =2 , I want 'x' to be named 'x2'

is this possible? Can I do a loop which can check the value of A and then re-name the array, 'x'?

Thanks for your help!

Subject: Variable names

From: Steven Lord

Date: 12 May, 2009 14:15:16

Message: 2 of 3


"M K" <maha_k@mathworks.com> wrote in message
news:gubuf2$t33$1@fred.mathworks.com...
> An array 'x' is dependent on a value of 'A'. I would like the name of 'x'
> be
> dependent on the value of 'A'. for example
> if A =1 , I want 'x' to be named 'x1' and
> if A =2 , I want 'x' to be named 'x2'
>
> is this possible?

Possible? Yes. Discouraged? Yes.

> Can I do a loop which can check the value of A and then re-name the array,
> 'x'?

Don't do this. See Q4.6 in the newsgroup FAQ:

http://matlabwiki.mathworks.com/MATLAB_FAQ

If A can only take on positive integer values, use a regular vector or a
cell array.

--
Steve Lord
slord@mathworks.com

Subject: Variable names

From: Loren Shure

Date: 12 May, 2009 15:51:21

Message: 3 of 3

In article <guc09j$5qh$1@fred.mathworks.com>, slord@mathworks.com
says...
>
> "M K" <maha_k@mathworks.com> wrote in message
> news:gubuf2$t33$1@fred.mathworks.com...
> > An array 'x' is dependent on a value of 'A'. I would like the name of 'x'
> > be
> > dependent on the value of 'A'. for example
> > if A =1 , I want 'x' to be named 'x1' and
> > if A =2 , I want 'x' to be named 'x2'
> >
> > is this possible?
>
> Possible? Yes. Discouraged? Yes.
>
> > Can I do a loop which can check the value of A and then re-name the array,
> > 'x'?
>
> Don't do this. See Q4.6 in the newsgroup FAQ:
>
> http://matlabwiki.mathworks.com/MATLAB_FAQ
>
> If A can only take on positive integer values, use a regular vector or a
> cell array.
>
>

If not, or even if perhaps, use dynamic field names to name the fields
of a struct.

--
Loren
http://blogs.mathworks.com/loren

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