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.

采纳的回答

Aakash
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 个)

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by