Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Basic Matlab Question
Date: Tue, 17 Nov 2009 15:33:03 +0000 (UTC)
Organization: Emo Labs
Lines: 21
Message-ID: <hdufnf$mv1$1@fred.mathworks.com>
References: <hdso7p$sh5$1@fred.mathworks.com> <hdsqh1$flv$1@fred.mathworks.com> <hducuk$r51$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1258471983 23521 172.30.248.37 (17 Nov 2009 15:33:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 17 Nov 2009 15:33:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1212210
Xref: news.mathworks.com comp.soft-sys.matlab:585798


...
> NO.  Do NOT use EVAL like this.  See Q4.6 in the newsgroup FAQ for an 
> explanation why this is a Bad Idea.
> 
...
> To the OP:  I would instead just use S(n, :) wherever in your code you would 
> have used A1, A2, ... or A(1), A(2), ...  IMO it's no more difficult to read 
> than A1, A2, A(1), A(2), etc. and it avoids creating lots of smaller 
> variables in your workspace.
> 
> -- 
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ 
> 

From the FAQ mentioned, "Now, if you still really want to create variables with dynamically generated names, you need to use EVAL. With EVAL, you use MATLAB commands to generate the string that will perform the operation you intend."

I agree this is not the best way to go about things and I wouldn't do it, but the FAQ itself spells out how to do what the OP wants to do using EVAL.

My advice to the OP is use what works for you to solve your problem.  When you get more experience with Matlab, follow Steve's advice above and use S(n, :) instead of creating more variables.