MATLAB: Do I get “Error using fopen” when using S-Function Builder Block in MATLAB R2018a

simulink

Using the S-Function Builder Block in R2018a, I get the following error when I click the "Build" button:
Error using fopen
The file name contains characters that are not contained in the filesystem encoding.
Certain operations may not work as expected.

Best Answer

We are currently aware of three possible causes for this error message:
1) The error may be due to an invalid character somewhere in a filename or its directory path. Please double-check all paths for any invalid characters that may exist by inspecting the output given by MATLAB when executing:
>> matlabroot
>> pwd
>> tempdir
in the current directory where your project files are located and from where you are building the S-Function.
2) In R2018a and prior, spaces in the temporary directory path have caused this issue, for example:
>> tempdir
ans =
'C:\Users\John Doe\AppData\Local\Temp'
You can work around this by changing the temporary directory to a folder without spaces at the beginning of your MATLAB session, using the SETENV command. For example:
>> setenv('TMP','C:\test')
This cause has been fixed in R2018b.
3) The localization settings on your computer might not be set properly and cause "fopen" to therefore see some irregular characters. For reference, please refer to the following link about the required locale settings:
Please ensure that the user locale and system locale are the same value. If they are different, this might be the reason for the S-Function builder error you are seeing. You might need to restart your computer after making any changes to locales.
You may also check your locale settings by entering the following commands into MATLAB Command Window and see if they match:
>> get(0, 'Language')
>> locale = java.util.Locale.getDefault()
>> language = locale.getLanguage()