MATLAB: I wrote codes which create a microsoft word and writes something inside it. I want to create a pushbutton which enables users to choose filename and directory to saving this file.

fprintf

parameters = 0:.1:1
A = [ parameters ; exp( parameters )]
fileID = fopen('results.doc','w')
fprintf(fileID,'%6s %12s\n','parameters ','rms')
fprintf(fileID,'%6.2f %30.8f\n',A)
fclose(fileID)
%as you see that users cannot choose directory or filename in these codes. I want to create a pushbutton in GUI for saving this doc file. When users push the button a dialog box which enables users to choose filename and directory for saving this file needs to open.
What kind of codes I need?

Best Answer

Use GUIDE to create a GUI. Place a pushbutton on your form. In the callback function for the pushbutton, put this code:
% Get the name of the file that the user wants to save.
startingFolder = userpath % or wherever you want
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)