|
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
|