genvarname({'A', 'A', 'A', 'A'});
Afficher commentaires plus anciens
Hi I would like to use genvarname({'A'}) but it should be dynamic times, like A1,A2,A3,....,An, as much as i want. I am not interest to write it like v = genvarname({'A', 'A', 'A', 'A'}); (5 times). Hope you the people understand why I do not want to write of it.
3 commentaires
It is such a terrible idea to generate variable names dynamically. No matter how much beginners keep inventing it and thinking that it would be a great idea for their code, this is one of the worst ways to write code.
Make your code faster, robuster, and neater by avoiding dynamically defined variable names. Properly written code is easier to understand, easier top debug, and easier to write: dynamically defined variable names are the opposite of all of these:
Azzi Abdelmalek
le 22 Avr 2016
Nothing is indicating that he is creating variables, they are just strings!
Sean de Wolski
le 22 Avr 2016
I'll give him the benefit of the doubt that he is setting the VariableNames property of a table. This will likely be more and more common as tables start to get more use and the default variable names of Var1, Var2, ... Varn are less explanatory than Sensor1,Sensor2, ... SensorN.
Réponse acceptée
Plus de réponses (2)
Jos (10584)
le 22 Avr 2016
0 votes
Why do you want to do this? It is generally a very bad programming idea to generate variable names like this.
"It is the contents of a variable that should change, not the name of the variable!"
Jos (10584)
le 22 Avr 2016
GENVARNAME will become obsolete pretty soon. This is more flexible:
C = arrayfun(@(k) sprintf('Sensor%02d',k), 7:13, 'un',0)
Catégories
En savoir plus sur Common Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!