Thread Subject: num2str in loop

Subject: num2str in loop

From: simon ott

Date: 20 Jan, 2009 00:22:01

Message: 1 of 3

hello
I want to assign the name of a variable based on loop iteration.

b = [3 4 ]

Iteration = 1: 2

['abc' num2str(Iteration)] = b(i)

End


But it does not work

Any hint ?

Subject: num2str in loop

From: Sadik

Date: 20 Jan, 2009 00:30:06

Message: 2 of 3

"simon ott" <simon_ott@yahoo.com> wrote in message <gl35f9$arm$1@fred.mathworks.com>...
> hello
> I want to assign the name of a variable based on loop iteration.
>
> b = [3 4 ]
>
> Iteration = 1: 2
>
> ['abc' num2str(Iteration)] = b(i)
>
> End
>
>
> But it does not work
>
> Any hint ?

Yes, that wouldn't work. Have you tried using eval as follows?

eval(['abc' num2str(Iteration) '= b(i);'])

Subject: num2str in loop

From: Matt Fig

Date: 20 Jan, 2009 01:27:01

Message: 3 of 3

Wow, I have never seen so many of these in such a short period of time!


It is very much recommended that you do not do this. Use cell arrays instead.

http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F




\RN\Y\YNlalsXsUb\ZN]\NllTlVza:N2fFlR]\[Uc'-alOOlbRN[ZRNUPPV

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
faq_4point6 Matt Fig 20 Jul, 2009 12:11:16
rssFeed for this Thread
 

MATLAB Central Terms of Use

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 Terms prior to use.

Contact us at files@mathworks.com