How do I use writetable to output a filename depending on my input?
5 次查看(过去 30 天)
显示 更早的评论
For example,
data = input('Input your excel file: ','s');
So, if I am to put my input of '15th of June', I want to get an output of
Table; % assuming I've coded some things based on data and my final product is Table
writetable(Table,'Schedule for 15th of June.xlsx');
But the data input may change and I want the default to be 'Schedule for "data".xlsx'. I can't figure how to do it. I've noticed that the file name has to be purely text.
I've also looked at the possibility of naming the 'Table' as the table;
Schedule_for_15th_of_June;
writetable(Schedule_for_15th_of_June);
But I know that that will only output a file in .txt, while my desired file type is .xlsx. I want to change writetable to make it so the default output is .xlsx but I don't know how to and I'm afraid it'll break the function. I appreciate any of your help in advance.
0 个评论
采纳的回答
Aakash
2023-6-15
Create filename before passing it to writetable using sprintf as below:
filename = sprintf('Schedule for %s.xlsx', data);
writetable(table, filename, 'FileType', 'spreadsheet');
Hope this helps you!!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!