create csv file with user input and current date as name
7 views (last 30 days)
Show older comments
Hello everyone
I want to create a csv file in desired location with name that include user input and current date.
I manage to create a csv file with the user input and the current date but I'm unable to save it in desired location
SN = input('Please enter the Serial Number ', 's');
fileName = sprintf('freq_res_data_%s_%s.csv',SN, datestr(now,'dd_mm_yy_HHMMSS'));
csvwrite(fileName,out);
I tried to run add the full direction (d:\tom\) but it doesnt work
I tried only on d:\ and it still deson't work
SN = input('Please enter the Serial Number ', 's');
fileName = sprintf('d:\tom\freq_res_data_%s_%s.csv',SN, datestr(now,'dd_mm_yy_HHMMSS'));
csvwrite(fileName,out);
tom folder is exist
how can I save in any other directory then the current folder?
0 Comments
Answers (2)
Benjamin Thompson
on 11 May 2022
Use sprintf to generate a local string variable. Use a \\ sequence to include a single \ in the string. Then pass the string as a filename to csvwrite.
» SN = '2'
SN =
'2'
» fileName = sprintf('d:\\tom\\freq_res_data_%s_%s.csv',SN, datestr(now,'dd_mm_yy_HHMMSS'))
fileName =
'd:\tom\freq_res_data_2_11_05_22_075347.csv'
2 Comments
Benjamin Thompson
on 11 May 2022
Please post the code and any errors you are getting from MATLAB. Remove semicolons after statements so you can see return results.
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!