MATLAB: Save button in GUI Matlab

cell arraysguimatlab guimatricessave

Hello,
I am developing a GUI and to save the files, I am currently using this commad
save('SystemMatrices.mat','Mass_Global', 'Damp_Global', 'Stiffness_Global','GlobalMesh')
% this is my save button
function SaveGlobal_Callback(source,eventdata)
[file,path,indx] = uiputfile();
end
I created a save button, but what should i write in it so that the user can choose the location and the name for the file to save. Basically it should be similar, but the user can choose the saving directory, and save 'Mass_Global', 'Damp_Global', 'Stiffness_Global','GlobalMesh in one file
I read this documentation:
but I dont know how it can be applied here
Does anybody know ?

Best Answer

Here, your code could be something like this. Keep in mind variable scope in functions. If the specified variables do not exist in your callback function, you'll need to pass them in or create them inside the function. Since I don't know how they are created, i've left that open ended here.
% this is my save button
function SaveGlobal_Callback(source,eventdata)
Mass_Global = ...;
Damp_Global = ...;
Stiffness_Global = ...;
GlobalMesh = ...;
[file,path] = uiputfile('*.mat');
save(fullfile(path,file),'Mass_Global', 'Damp_Global', 'Stiffness_Global','GlobalMesh')
end