Combining 2 Cell elements as a single element
이전 댓글 표시
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
Alexandra Harkai
2016년 11월 29일
Since this kind of variable names are generally advised against, may I ask why do you need the variable names in this format?
답변 (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.
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!