Why do I get a Simulink diagnostic error saying "Error opening or closing file'"?
46 views (last 30 days)
Show older comments
MathWorks Support Team
on 18 Jan 2019
Edited: MathWorks Support Team
on 30 Nov 2020
Why do I get a Simulink diagnostic block error saying:
Diagnostic reported from block 'myModel/From File'
Caused by:
Error opening or closing file 'myFile.mat'
Accepted Answer
MathWorks Support Team
on 1 Dec 2020
Edited: MathWorks Support Team
on 30 Nov 2020
When the error is reported from a "From File" block:
Possible causes for the error message may be the following:
1. The "From File" block only works for regular binary MAT-files, not for any text-based ASCII files. To test if your MAT-file is an ASCII file, run the following command on it and see of the following error message appears:\nTo generate a binary MAT-file, make sure that you create your MAT-file by using the "save" command, instead of file I/O commands ("fopen","fwrite",etc.).
>> matfile('myFile.mat');
Unable to read MAT-file
C:\temp\myFile.mat:
not a binary MAT-file.
2. Verify that you are able to load your MAT-file into workspace using the "load" command:\nIf this fails, your MAT-file is corrupt and will not work with the "From File" block either.
>> load('myFile.mat');
3. This diagnostic may indicate that the MAT-file is a location where the user does not have read permissions. Contact your system administrator for further assistance.
When the error is reported from a "To File" block:
This diagnostic can indicate that the MATLAB current folder path is a location where the user does not have read/write permissions. To figure out your MATLAB current folder path, use the command "pwd" or look in the MATLAB current folder toolbar.
To work around the issue, contact your system administrator to give read/write permissions, or change your MATLAB current folder path to another location.
0 Comments
More Answers (0)
See Also
Categories
Find more on Configure and View Diagnostics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!