MATLAB: Pass Parameters to Script

argumentscommandslive scriptparametersscript

Hello All,
I wanted to know if anyone knows if it's possible to pass arguments to a matlab script file, perhaps similar to the built-in commands like clear.
My motivation for wanting to do this instead of using a function file is that in my case, I would strongly prefer all variables used to remain in the workspace so that I can continue playing around with them. One option would be to put everything into a struct and have the function output that struct, but this is very cumbersome and muddles up the script. Thus far I've been putting flags at the beginning of the script (such as "save = true" or "filename = 'FN'") and commenting and uncommenting them as necessary, but as their number has grown and I switch more frequently it would be great to be able to avoid having to open and edit the file so frequently.
Many thanks! Andrew

Best Answer

This FEX submission makes it very easy to export variables to the base workspace
W = who;
putvar(W{:})