Change variable's names with one character?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi. Suppose I have these variables:
a=1
b=2
c=3
And I want to change their names by adding the number assigned here:
x = 1
So I will have:
a1= 1
b1= 2
c1= 3
Is possible to do that without a loop?
Thanks
1 comentario
Stephen23
el 5 de En. de 2020
Editada: Stephen23
el 5 de En. de 2020
There are certainly ways to do this, if you want to force yourself into writing slow, complex, buggy code that is hard to debug:
Much better is to learn how to use arrays and indexing, just like experienced MATLAB users. Indexing is neat, simple, easy to debug and very efficient. Unlike what you are trying to do.
Respuestas (1)
Image Analyst
el 5 de En. de 2020
Editada: Image Analyst
el 5 de En. de 2020
Yes
a1 = a;
b1 = b;
c1 = c;
Note though that a1 and a do not refer to the same memory location so changing a1 will not automatically change a, and changing a will not automatically change a1.
Ver también
Categorías
Más información sobre Variables 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!