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
Subject: Re: how to rename a workspace variable in a loop?
"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
Subject: Re: how to rename a workspace variable in a loop?
"Rick Rosson" <rrosson@mathworks.com> wrote in message
news:f7oloa$75a$1@fred.mathworks.com...
> 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
>
>
Subject: Re: how to rename a workspace variable in a loop?
"Nizar " <pakoeli@hotmail.com> wrote in message <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.
Don't. See question 4.6 in the newsgroup FAQ for some of the reasons you shouldn't do this and alternatives to doing this.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.