Creating .csv file using fprintf - file is locked by 'another user'
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jan
2011-2-9
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!