create csv file with user input and current date as name

4 次查看(过去 30 天)
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?

回答(2 个)

Benjamin Thompson
Benjamin Thompson 2022-5-11
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 个评论
Tamir Yakobov
Tamir Yakobov 2022-5-11
thanks,
its working in d:\ and d:\tom directories but it's not working on c:\
any idea why?
Benjamin Thompson
Benjamin Thompson 2022-5-11
Please post the code and any errors you are getting from MATLAB. Remove semicolons after statements so you can see return results.

请先登录,再进行评论。


Tamir Yakobov
Tamir Yakobov 2022-5-11
>> test
Please enter the Serial Number 777
SN = 777
fileName = c:\freq_res_data_777_11_05_22_171425.csv
error: dlmwrite: Invalid argument
error: called from
dlmwrite at line 177 column 5
csvwrite at line 44 column 3
test at line 22 column 1
>> test
Please enter the Serial Number 777
SN = 777
fileName = d:\freq_res_data_777_11_05_22_171444.csv
can it be a permission issue?

标签

Community Treasure Hunt

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

Start Hunting!

Translated by