Thread Subject: Names of Variables stored in other variables

Subject: Names of Variables stored in other variables

From: nissan.aloni@intel.com

Date: 2 Apr, 2006 23:25:50

Message: 1 of 3

hi,

can i refer to a variable whos name is stored in another varialbe?

e.g. :
MyVar = [1 1 1];
a = 'MyVar';

Can i get to the values stored in MyVar using only the "a" variable?

thanks

Subject: Names of Variables stored in other variables

From: French Caro

Date: 3 Apr, 2006 04:35:17

Message: 2 of 3

Hi,
>
> Can i get to the values stored in MyVar using only the "a"
> variable?
>
Yes you can but it is not recommended :
help eval
example :
value2 = eval([a,'(2)']);

Caroline

Subject: Names of Variables stored in other variables

From: David Mackenzie

Date: 3 Apr, 2006 01:30:36

Message: 3 of 3

Caroline is right. You might want to consider changing your
application to make use of MATLAB structures - their fields can be
accessed dynamically by name (see "Programming and Data Types:
Structures and Cell Arrays: Accessing Data in Structure Arrays" in the
MATLAB help).

David

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com