MATLAB: Using save(Filename) in a Callbackfunction of a button

matlab gui

I am programming a GUI and i want to save data in a callback function in matfile. I was under the impression, that if i use save only the functions workspace will be saved. Does hObject include all GUI objects in the function workspace?
save_pushbutton = uicontrol('Parent', tab ,'Style','pushbutton','Callback',@save_callback,...
'String','Save',...
'FontSize',8,...
'Units', 'normalized', 'Position',[.15 .05 .1 .05]);
editfield = uicontrol('Parent', tab ,'Style','edit','Callback',@input_control,...
'String','',...
'FontSize',8, 'TooltipString', ['Input must be numerical'], ...
'Units', 'normalized', 'Position',[.15 .8 .1 .05]);
function save_callback(hObject, eventdata)
x = get(editfield,'String');
save('save.mat');
end
In this example i want to save x in the mat file. Since i have a lot of variables i tried to keep it short and not name them all individually (save(Filename,x,y…).
Edit: Apparently there is a GUI workspace and GUI/callback workspace. I only want to save the GUI/callback.
Edit: Added more code

Best Answer

"I was under the impression, that if i use save only the functions workspace will be saved."
Yep, as confirmed by,
help save
save Save workspace variables to file.
save(FILENAME) stores all variables from the current workspace in a
MATLAB formatted binary file (MAT-file) called FILENAME
"Does hObject include all GUI objects in the function workspace?"
No. hObject, which is the handle to the GUI object that contains the save_callback() callback function.
Your save() funciton call should do what you're describing. It should save all variables in the save_callback() workspace that come prior to save(). If you're just trying to save the variable x,
save('filename.mat', 'x');
Related Question