MATLAB: Pass variable’s through the run command

MATLABmenurun

I have made a menu, instead of me asking the same questions at the start of each matlab file. would it be possible using run command to pass over a variable. If this is possible would it be possible to pass variables back from the running m file to the menu ?

Best Answer

  • "would it be possible using run command to pass over a variable."
    No, never. If you need to pass variables you should be using a function and calling it. run() is reserved for use with scripts, which are defined as not passing variables.
    You can assign to a variable that happens to be used in the script you run(). run() invokes scripts, and by definition scripts execute in the same workspace as they are called from and so have full access to the variables in that workspace.