How can I get dynamic naming variables? So in a loop i need variables with names A1,A2,A3...... logic?

1 visualización (últimos 30 días)
the loop running should produce N outputs with each having label A1,A2,A3....An

Respuestas (1)

CS Researcher
CS Researcher el 1 de Mayo de 2016
You can use eval. Try this:
for i = 1:10
eval(['A' num2str(i) ' = i;']);
end
  2 comentarios
ck
ck el 1 de Mayo de 2016
so I have An = strcat(1,2,3..) and n in the loop where It should go as A1,A2.....
can I use eval for that?
Stephen23
Stephen23 el 1 de Mayo de 2016
Editada: Stephen23 el 19 de Jun. de 2019
Note that this forces you into writing slow, buggy, obfuscated code, that removes all of MATLAB code checking abilities and makes code difficult to debug.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by