Clearing Global variables... except for.
54 views (last 30 days)
I wish to clear all my global variables apart from two. So I've generated a cell array of strings that contain all my global variables and removed the two I wish to save:
globals = who('global');
globals = globals(~strcmpi(globals,'waitGUI'));
globals = globals(~strcmpi(globals,'decayFig'));
This is where I'm stuck. How do I clear all the variables who's names of the variables are strings within the cell array "globals"? Thanks!
Image Analyst on 11 Oct 2012
Here's one way. Just save what you want into local variables, then destroy all globals, then recreate the globals you want:
% Save into local variables.
saved_waitGUI = waitGUI;
saved_decayFig = decayFig;
% Clear all globals
% Redeclare globals
% Restore the globals we wanted to keep
waitGUI = keep_waitGUI;
decayFig = keep_decayFig;