Creating .csv file using fprintf - file is locked by 'another user'
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Jan
el 9 de Feb. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!