Borrar filtros
Borrar filtros

How can I create variables with for loop?

11 visualizaciones (últimos 30 días)
muly san
muly san el 15 de Ag. de 2013
I want somthing like this:
for i=1:3;
j`i'=i;
end
The output shuld be:
j1=1 j2=2 j3=3
thanks!

Respuestas (3)

James Tursa
James Tursa el 15 de Ag. de 2013

Image Analyst
Image Analyst el 15 de Ag. de 2013

Ilham Hardy
Ilham Hardy el 15 de Ag. de 2013
Editada: Ilham Hardy el 15 de Ag. de 2013
Use eval
To know more about eval function, type doc eval in your command window.
To know more about why you should avoid eval, wait an pay attention to comment on this answer :P
  1 comentario
Jan
Jan el 15 de Ag. de 2013
Oh no, Ilham Hardy, do not suggest eval() never ever and under no circumstances. It is evil and eats up the programmers trials to write clear, clean and efficient code. There is always a better solutions. The topic has been discussed often enough and is found in the FAQs.
Satisfied? :-)

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by