Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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

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.

Contact us