Effacer les filtres
Effacer les filtres

impossible to accede to a file with fopen

1 vue (au cours des 30 derniers jours)
Damien DUDUYER
Damien DUDUYER le 22 Mai 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

Réponses (1)

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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Low-Level File I/O dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by