Path: news.mathworks.com!not-for-mail
From: "Rick Rosson" <rrosson@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to rename a workspace variable in a loop?
Date: Thu, 19 Jul 2007 17:40:24 -0400
Organization: The MathWorks, Inc.
Lines: 46
Message-ID: <f7oloa$75a$1@fred.mathworks.com>
References: <f7olca$1mj$1@fred.mathworks.com>
Reply-To: "Rick Rosson" <rrosson@mathworks.com>
NNTP-Posting-Host: rossonr.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1184881226 7338 144.212.206.185 (19 Jul 2007 21:40:26 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 19 Jul 2007 21:40:26 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
Xref: news.mathworks.com comp.soft-sys.matlab:419997


Use the EVAL function

Type:

   doc eval

at the command prompt.


For example:

  for i = 1:5

     ...
     ...

     eval([ 'M' num2str(k) ' = M;' ]);

     ...
     ...

  end




"Nizar " <pakoeli@hotmail.com> wrote in message 
news:f7olca$1mj$1@fred.mathworks.com...
> Hi,
>
> I was wondering how you could rename a workspace variable in a loop? What 
> I have is a loop that generates results which are stored in a matrix. the 
> problem is that in the 2nd loop the matrix is overwritten. I also cannot 
> add both matrices, because they are not of the same size.
>
> Therefore i wanted to know how to rename the workspace variable for each 
> loop generation. for example when using a "for" loop with i=1:1:5 how can 
> I name the matrix M for each loop with a increment, thus M1, M2, M3, 
> etc... so that I can analyze all the data and not that of only the last 
> loop.
>
> any suggestions are appreciated.
>
> thank you