Can I create local function variables at runtime and are how are they evaluated subsequently?

I am using a parent function that calls another child (nested) function. This child function creates a new variable inside the parent's local workspace, using "assignin('caller', 'newVariable')". How can I use this "newVariable" in the parent function's body to evaluate it?

 Accepted Answer

In order to use the dynamically created variable in the parent function, you need to do EITHER:
1) directly type the variable name in the code to match the name created and runtime. Ensure you are not shadowing any builtin variables, objects or functions. Otherwise the coded evaluation of the variable will be parsed at the beginning of runtime and the shadowed variable will be used instead.
OR
2) use dynamic name generation, like shown in these examples:

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!