MATLAB: How to request user input to save figure? uiputfile command does not create the file after clicking ‘Save’

modal dialog boxsaving figureuiputfileuisave

I would like to request user input and modal dialog box to save figure after plotting from the .mat file. But the uiputfile command does not create any file after clicking on 'Save'. The same happened when I tried to save .mat files but I switched to 'uisave' command and the issue was sorted. But the issue remains with saving the figure. Any help would be appreciated.

Best Answer

The uiputfile only creates the filename and filepath based on where the user wants to save the file. You need to actually write the save command AFTER uiputfile.
[filename, pathname] = uiputfile('*.mat', 'Save the file as');
if isnumeric(filename)
disp('User pushed cancel. Not saving anything')
else
save(fullfile(pathname, filename), 'Var')
end