Convert string to variable.
이전 댓글 표시
I'm pulling a string from a table 'Matrix1'. Before that, I have defined Matrix1 as an actual matrix. What I want to do is pull the string from the table and have matlab recognize the name and use the matrix. I have to pull it from the table, because the table is changing and may sometimes say 'Matrix2' or 'Matrix3'.
So what I have now is a table (named 'Table') and a column (named 'Territory'). I'm using the command Table.Territory(3) to access the third territory in the list. But it comes through as a string and I need it to come through as a matrix. I have already saved that territory name as a matrix.
댓글 수: 3
Steven Lord
2022년 7월 14일
Can you dynamically create and reference variables with numbered names like x1, x2, x3, etc.? Yes.
Should you do this? The general consensus is no. That Answers post explains why this is generally discouraged and offers several alternative approaches.
DKonk
2022년 7월 14일
"I'm not entirely sure what a dynamic variable is, but I'm fairly sure I dont want to do this."
Yet it seems to be exactly what you are attempting. Which would force you into writing slow, complex, inefficient, obfuscated, insecure, buggy code which is hard to debug... just to access your data:
Best avoided.
"So I have an excel doc that will be changing frequently (maybe this makes it dynamic?)"
No, the fact your file can change is unrelated.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!