Can xlswrite be used to prompt the user for the file name?
2 次查看(过去 30 天)
显示 更早的评论
I have a script that writes the results to an excel file. Currently the file name has to be entered into the script. I want the user to enter the name when prompted by the script. How can I this be done?
0 个评论
回答(3 个)
Image Analyst
2015-8-1
Try this:
% Get the name of the file that the user wants to save.
startingFolder = userpath % Or pwd, or wherever you want it to start at.
defaultFileName = fullfile(startingFolder, '*.xlsx');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a filename ');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
% Combine the folder and base file name into the full file name.
fullFileName = fullfile(folder, baseFileName)
% Write the data out to the filename the user has chosen.
xlswrite(fullFileName, data);
0 个评论
Jon
2015-8-1
This code will request user input for the name:
str = input('Enter filname:','s')
Then you can simply pass the str variable into xlswrite:
xlswrite(str,A)
Is that what you're asking?
2 个评论
Jan
2015-8-1
Use uigetfile, if the file is existing already and the data should be appended, and uiputfile if the file should be created or overwritten.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!