Simple xlswrite question.

1 次查看(过去 30 天)
Francois Desmeules
Francois Desmeules 2016-10-20
Hello,
I have a few matrices that I want to export in excel. Every time I run my code, I want to export few outputs in Excel. From what i've found I have to hardcode the file name, by doing that I am always writing in the same file. I need to find a way to always create a new file or clear the content of the same file before writing in it.
Thanks

回答(1 个)

Image Analyst
Image Analyst 2016-10-20
Try uiputfile() and let the user specify the name by typing it in:
% Get the name of the file that the user wants to save.
% Note, if you're saving an image you can use imsave() instead of uiputfile().
startingFolder = userpath % Or "pwd" 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)
Or you can create the filename from values of some of your variables if you use sprintf().

产品

Community Treasure Hunt

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

Start Hunting!

Translated by