matlabundocumented-behavior

How to hide a variable from workspace in matlab


Is there an undocumented way to render a variable 'invisible' in matlab such that it still exists but does not show up in the workspace list?


Solution

  • One thing you can do is have global variables. An interesting property of these is that even when you clear the workspace they still exist in memory unless you clear global variables specifically. An example is below.

    global hidden_var
    hidden_var = 1;
    clear
    global hidden_var
    hidden_var
    

    I'm still not entirely sure why you would even want the feature but this is a way that you can "hide" variables from the workspace.