Creating .csv file using fprintf - file is locked by 'another user'
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I am using fprintf to output variables of several different classes into a .csv file. I am using the following approach;
somedata={x x; x x; x x;};
[nrows ~] = size(somedata);
fid = fopen('myfile.csv','w');
for ii=1:nrows
fprintf(fid,'%f %f\n',somedata{ii,:}
end
fclose(fid)
When I go to open the .csv file in Excel, it claims that the file is locked for editing by 'another user'. I presume Matlab still has the file in memory or something which is making Excel cry.
How do I correct this?
thanks, Alex
0 Kommentare
Akzeptierte Antwort
Jan
am 9 Feb. 2011
You closed the file correctly with FCLOSE. The problem is not included in the posted code. I assume, you have open the file before but did not close it, e.g. because the program stopped with an error. Then let Matlab close all open files:
fclose('all');
If this does not help, another application uses the file. Just restart the corresponding application and try to open the file in Excel again.
Ever check, if FOPEN could open the file:
fid = fopen('myfile.csv','w');
if fid == -1, error('Cannot open file'); end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!