Can xlswrite be used to prompt the user for the file name?

10 visualizaciones (últimos 30 días)
David Hughes
David Hughes el 1 de Ag. de 2015
Comentada: Image Analyst el 2 de Ag. de 2015
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?

Respuestas (3)

Image Analyst
Image Analyst el 1 de Ag. de 2015
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);

Jon
Jon el 1 de Ag. de 2015
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 comentarios
David Hughes
David Hughes el 2 de Ag. de 2015
Yes this what I wanted. Also I am looking for the prompt to be a dialog box.
Image Analyst
Image Analyst el 2 de Ag. de 2015
That's what I gave you. Did you overlook my answer below?

Iniciar sesión para comentar.


Jan
Jan el 1 de Ag. de 2015
Use uigetfile, if the file is existing already and the data should be appended, and uiputfile if the file should be created or overwritten.

Categorías

Más información sobre Calendar en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by