Combining 2 Cell elements as a single element
Mostrar comentarios más antiguos
I can't really describe the problem I am having. Here is the code so far,
rows={'r','r','r','r','r','r','r','r','r'};
cols={'c','c','c','c','c','c','c','c','c'};
r=genvarname(rows);
c=genvarname(cols);
I am looking to create a 9x9 grid, in which is of the format rc, r1c1,r2c2,r3c3...r9c9. Each variable will also have multiple values stored as matrices eg, r1c1=[1,2,3].
// I am writing on the R2015a software, but will be doing most of the work on R2016a at home.
1 comentario
Alexandra Harkai
el 29 de Nov. de 2016
Since this kind of variable names are generally advised against, may I ask why do you need the variable names in this format?
Respuestas (1)
Do not create variables dynamically. This is a really bad programming practize and you find dozens of discussions to this topic in the forum. E.g.: http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
The complicated methods to create variables dynamically demand for even more complicated methods to access them later on. The runtime degrades remarkably (factor of 100 is possible) and debugging gets horror. Use arrays and indexing instead of hiding the indices in the names of the variables.
Categorías
Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!