xlswrite and more efficient coding

5 次查看(过去 30 天)
Dear all,
I have the following command
xlswrite('data_Aus_Di_out'1.xlsx', yy ,'Sheet1', 'A2')
I would like to have something like
k={'data_Aus_Di_out'}
xlswrite('k.xlsx', mdata1 ,'Sheet1', 'A2')
so as to be able to change the name of the excel file OUTSIDE the lxswrite function
thank you

采纳的回答

Image Analyst
Image Analyst 2012-7-3
编辑:Image Analyst 2012-7-3
Use sprintf() to create whatever base filename you want. Use fullfile() to combine the folder and the base filename into the full path (folder plus base filename). Also, see the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F for examples of how to create a variety of filenames in different ways.
% Make a base file name that has a number embedded in it.
baseFileName = sprintf('dataoutput_Austria_Diapers_output%d.xlsx', k);
% Combine it with the folder to get the full path of the file.
fullFileName = fullfile(folder, baseFileName);
% Now write it out to an Excel workbook.
xlswrite(fullFileName, mdata1 ,'Sheet1', 'A2');
  7 个评论
Sabbas
Sabbas 2012-7-4
编辑:Sabbas 2012-7-4
I think that the easiest approach is the following
k='output1.xlsx'
xlswrite(k, yy ,'Sheet1', 'A2')
Am I right? In this way I do not need to use "fullfile" etc..
Image Analyst
Image Analyst 2012-7-4
Sure, that's easier, but not as robust. If you know for a fact that you always want to put your workbook in the same folder as your m-file, rather than, say the folder where your input data came from or somewhere else, then you can omit the folder and store it in whatever the current directory is. I recommend you read the FAQ: http://matlab.wikia.com/wiki/FAQ#Where_did_my_file_go.3F_The_risks_of_using_the_cd_function. so you don't specify where the workbook should go via the cd function.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by