Thread Subject: genvarname (alternative to for Matlab v6.5)

Subject: genvarname (alternative to for Matlab v6.5)

From: supandey@yahoo.com

Date: 29 Jan, 2009 22:54:46

Message: 1 of 3

Hello, I have an old version of Matlab (v6.5) and wonder if there is
an alternative to genvarname I can use? What I would like to do is:

x= {'aa', 'bb'};
[x(1), x(2)] = textread('MyFile.txt','%f%f','delimiter',',');

but this will not work as one needs to convert x(1) to a variable via
genvarname(x(1))

Thanks,
Sanjeev

Subject: genvarname (alternative to for Matlab v6.5)

From: Steven Lord

Date: 30 Jan, 2009 14:57:17

Message: 2 of 3


<supandey@yahoo.com> wrote in message
news:ea4e5940-7468-4969-b8b9-c335c41cb396@l33g2000pri.googlegroups.com...
> Hello, I have an old version of Matlab (v6.5) and wonder if there is
> an alternative to genvarname I can use? What I would like to do is:
>
> x= {'aa', 'bb'};
> [x(1), x(2)] = textread('MyFile.txt','%f%f','delimiter',',');
>
> but this will not work as one needs to convert x(1) to a variable via
> genvarname(x(1))

You're trying to create variables named aa and bb (using the strings in x to
name the variables) to store the outputs from TEXTREAD?

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

http://matlabwiki.mathworks.com/MATLAB_FAQ

Dynamic field names were introduced in MATLAB 6.5 (R13), so you can use them
and I would recommend that approach for this example.

x = {'aa', 'bb'};
[S.(x{1}), S.(x{2})] = textread(...

While you _could_ use EVAL to do what you'd originally proposed, you'd have
to use EVAL everywhere later on in the code you wanted to refer to the aa or
bb variables. To me, that dramatically reduces the readability of your
code.

--
Steve Lord
slord@mathworks.com

Subject: genvarname (alternative to for Matlab v6.5)

From: supandey@yahoo.com

Date: 2 Feb, 2009 03:59:46

Message: 3 of 3

On Jan 30, 8:57=A0am, "Steven Lord" <sl...@mathworks.com> wrote:
> <supan...@yahoo.com> wrote in message
>
> news:ea4e5940-7468-4969-b8b9-c335c41cb396@l33g2000pri.googlegroups.com...
>
> > Hello, I have an old version of Matlab (v6.5) and wonder if there is
> > an alternative to genvarname I can use? What I would like to do is:
>
> > x=3D {'aa', 'bb'};
> > [x(1), x(2)] =3D textread('MyFile.txt','%f%f','delimiter',',');
>
> > but this will not work as one needs to convert x(1) to a variable via
> > genvarname(x(1))
>
> You're trying to create variables named aa and bb (using the strings in x=
 to
> name the variables) to store the outputs from TEXTREAD?
>
> Don't. =A0See Q4.6 in the newsgroup FAQ:
>
> http://matlabwiki.mathworks.com/MATLAB_FAQ
>
> Dynamic field names were introduced in MATLAB 6.5 (R13), so you can use t=
hem
> and I would recommend that approach for this example.
>
> x =3D {'aa', 'bb'};
> [S.(x{1}), S.(x{2})] =3D textread(...
>
> While you _could_ use EVAL to do what you'd originally proposed, you'd ha=
ve
> to use EVAL everywhere later on in the code you wanted to refer to the aa=
 or
> bb variables. =A0To me, that dramatically reduces the readability of your
> code.
>
> --
> Steve Lord
> sl...@mathworks.com

Thank you. That's exactly what I was looking for.
-Sanjeev

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