For your first question, I would suggest just putting a command like save('filename.mat');
in the "Save" button's callback. But what variables? If they are in the base workspace, see my answer to your second question below.
To load data into the base workspace, you might try the evalin
command:
evalin('base','load(''filename.mat'')');
The 'base'
argument tells it to run the command in the base workspace.
If your file name is in a variable:
fname = 'filename.mat';
evalin('base',['load(''' fname ''')']);
Alternatively, you could use sprintf
:
loadCmd = sprintf('load(''%s'')',fname);
evalin('base',loadCmd);