MATLAB: Do I get a Simulink diagnostic error saying “Error opening or closing file'”

simulink

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'

Best Answer

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:\n
>> matfile('myFile.mat');
Unable to read MAT-file
C:\temp\myFile.mat:
not a binary MAT-file.
To 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.).
2. Verify that you are able to load your MAT-file into workspace using the "load" command:\n
>> load('myFile.mat');
If this fails, your MAT-file is corrupt and will not work with the "From File" block either.
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.