Clear Filters
Clear Filters

impossible to accede to a file with fopen

1 view (last 30 days)
Damien DUDUYER
Damien DUDUYER on 22 May 2013
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

Answers (1)

Iain
Iain on 22 May 2013
Do not use fopen then try to use dlmwrite/csvwrite/etc.
  1 Comment
Damien DUDUYER
Damien DUDUYER on 23 May 2013
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.

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!