I need to generat a structure name
Show older comments
I need to generate a structure name during execution. The name is dependent on the value of a variable.
1 Comment
Stephen23
on 24 May 2017
Do not generate variable names dynamically:
Doing that will make your code slow, buggy, hard to debug, hard to read, and much more complicated than it needs to be. It is easy to learn how to write efficient code.
Answers (1)
While Stephen's answer is spot-on for variables, structures are different and can be manipulated more readily and without explicit eval code which is, indeed, slow and potentially very difficult to debug.
While it may or may not be the best way to proceed and we don't have sufficient information to be able to judge, the ability to create dynamic structure field names is described here:
NB: This is the name of a field within a statically-named structure, though, a far cry from the name of the structure itself being dynamic.
Categories
Find more on Whos 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!