I need to generat a structure name

I need to generate a structure name during execution. The name is dependent on the value of a variable.

1 Comment

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.

Sign in to comment.

Answers (1)

dpb
dpb on 25 May 2017
Edited: dpb on 25 May 2017
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.

Asked:

on 24 May 2017

Edited:

dpb
on 25 May 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!