impossible to accede to a file with fopen

1 次查看(过去 30 天)
With Matlab 2012b + simulink, I use a Matlab function to write data in a .txt file. Sometime, a problem to accede to the file occurs. The problem is that a window appears: title of the window is "Remote". The window contain the following text (in french): "Impossible to accede to the file "Elapsed_Real_Time.txt. Continue to try to communicate? YES/NO"
When the window appears, it stops the access to the file and the data is not written anymore.
The model was working with matlab 2007. Is it necessary to a code line to avoid the problem.
function Matlab_to_WM(u)
coder.extrinsic('dlmwrite');
coder.extrinsic('fopen');
coder.extrinsic('fclose');
fid=double(0);
fid=fopen('D:\damien\Echange_donnees_System\Elapsed_Real_Time.txt', 'w');
if fid ~= -1 && fid ~= 2
dlmwrite('D:\damien\Echange_donnees_System\Elapsed_Real_Time.txt' , u , 'newline', 'pc');
end
fclose('all');
end

回答(1 个)

Iain
Iain 2013-5-22
Do not use fopen then try to use dlmwrite/csvwrite/etc.
  1 个评论
Damien DUDUYER
Damien DUDUYER 2013-5-23
I forgot to specify that the .txt file is read by an other software. The txt file is used for data exchange. That's why I check whith fopen if the file is accessible or not. Without using fopen, I will have an error when dmlwrite try to write the data in the same time that the other software have opened the file to read the data.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Low-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