Why do I get an error when I try to write data into file?
1 view (last 30 days)
Show older comments
Commented: Hannah on 12 Aug 2021
I want to write "Formattyp = 1" into my file Batch.csv.
This is the section of my code:
myBatchName = '\\\\data-be\\data-ti-2019\\eit\\50_Labore\\T016-Photovoltaik_1\\06_Projekte\\02_Aktiv\\2019_Schenker_Storen\\DOCS_Hannah\\Experiment2\\02_Generate_Batch_File\\02-EXP2_Batch_Files\\Batch.csv';
fileID = fopen(myBatchName,'w'); %open file for writing; discard existing contents
fprintf(fileID,'Formattyp = 1\n');
But I keep getting this error:
" Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in EXP2_Ver1_Generate_Batch_File (line 111)
fprintf(fileID,'Formattyp = 1\n'); "
Which I do not understand because I have specified my fileID, so it should know where to write the data into. What am I doing wong? Thanks.
KSSV on 12 Aug 2021
Check the path of the file....check the value of fileID. If the file is not open properly, the value will be negative. There is probem with your filename/ path.
More Answers (0)
Find more on Low-Level File I/O 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!