Use text concatenated with GUI variable in filename

1 回表示 (過去 30 日間)
Deirdre
Deirdre 2014 年 2 月 3 日
編集済み: Azzi Abdelmalek 2014 年 2 月 3 日
I'm trying to open a file and write to it but I keep getting this error: "Error using fprintf, Invalid file identifier. Use fopen to generate a valid file identifier." I need the file name to be a text edit from a GUI (patientid) combined with the date and time.
code:
id = get(handles.patientid,'String');
filename = strcat(id,': ',datestr(now));
fileID = fopen(filename,'w');
fprintf(fileID,...);
fclose(fileID)
thanks!

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 3 日
編集済み: Azzi Abdelmalek 2014 年 2 月 3 日
The filename with : is not valid
try
id = get(handles.patientid,'String');
filename = strcat(id,datestr(now,'dd-mm-yyyy HH-MM-SS'),'.txt');
fileID = fopen(filename,'w');
fprintf(fileID,...);
fclose(fileID)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by