changing the name of a variable

Hi,
I know that what I am asking for is not recommended but I need it. I have a loop and i want to change the name of the variable according to the loop:
for i=1:40 variable L I want it to be named L1,L2...L40 according to the i value in the loop.is it possible to do so?

Respuestas (2)

Vishwajith Upendra
Vishwajith Upendra el 17 de Jul. de 2011
Here is a sample code which does what you want. Try it.
for i=1:5
x=num2str(i); % Converts number to string
x1=strcat('L',x); % Concatenates your prefix to the varying number
x1 % I guess, this is the variable you want
end
Hope it helped.

1 comentario

Oleg Komarov
Oleg Komarov el 17 de Jul. de 2011
I think it's more likely to be the faq 4.6 as Walter suggested, otherwise the OP should be more specific.
Walter Roberson
Walter Roberson el 16 de Jul. de 2011

0 votos

Please see the FAQ
Why do you "need" to do this? There is almost always a better way.

3 comentarios

joseph Frank
joseph Frank el 16 de Jul. de 2011
because I am building tables from all possible regression combinations and I am naming each table differently in order to save them all
Paulo Silva
Paulo Silva el 16 de Jul. de 2011
that's the reason for the existence of cells
Walter Roberson
Walter Roberson el 16 de Jul. de 2011
Sounds like a reason to use dynamic field names on a structure, and to use the '-struct' option of save()

La pregunta está cerrada.

Preguntada:

el 16 de Jul. de 2011

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by