Convert string to variable.
Show older comments
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 Comments
Steven Lord
on 14 Jul 2022
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
on 14 Jul 2022
"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.
Accepted Answer
More Answers (0)
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!