create csv file with user input and current date as name

조회 수: 4 (최근 30일)
Tamir Yakobov
Tamir Yakobov 2022년 5월 11일
답변: Tamir Yakobov 2022년 5월 11일
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?

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by