identical code works fine in matlab 2015b but not in matlab 2016b

1 view (last 30 days)
Hi, I'm using matlab coder that generates this code:
fileName = [fileName '.bin'];
fid = fopen(fileName, 'w');
if fid == -1
error(['Cannot open output file ' fileName ' for writing']);
% some code here
fwrite(fid, var1, 'int32');
While running the code created from the coder used in matlab 2015b it works without any errors. While running the code created from the coder used in matlab 2016b I get the following error:
Undefined function 'coder.internal.ifWhileCondExtrinsic' for input arguments of type 'logical'.
Error in fileManager>fileclose (line 143) if failp
Error in fileManager (line 23) f = fileclose(varargin{1});
Error in fclose (line 15) st = double(fileManager('close',fileID));
Error in coder_file_name (line 8) fclose(fid);
The fopen and fwrite works, as proof the file does created, But I do get the bizarre error. What is wrong?

Answers (2)

Steven Lord
Steven Lord on 2 Nov 2016
Have you created your own fclose function that's shadowing the one included in MATLAB? You can check this using the which function.
which -all fclose
In release R2016b the fclose.m file has a line 15. However since fclose is a built-in function fclose.m contains only help text and line 15 is a blank line, the last line in the file. That's why I suspect you've created your own function by that name. Rename or remove that function.
Steven Lord
Steven Lord on 2 Nov 2016
Okay, so it is MATLAB Coder itself that has defined a code generation version of fclose. I'm not very familiar with MATLAB Coder, so I don't know why that's not working. You're probably going to want to contact Technical Support via the Contact Us link in the upper-right corner of this page.

Sign in to comment.

Ryan Livingston
Ryan Livingston on 6 Nov 2016
Edited: Ryan Livingston on 16 Nov 2016
A MATLAB bug report has been published for this issue:
which contains a patch that can be applied into a MATLAB installation.
It looks like the function ifWhileCondExtrinsic may not be installed without MATLAB Coder being installed even though the MATLAB Coder MEX file is depending on that file. I reported this to the MATLAB Coder development team.
For a quick workaround, on your machine with MATLAB Coder you can run:
which coder.internal.ifWhileCondExtrinsic
and then copy that file to your machine which doesn't have MATLAB Coder to the directory:
where $MATLABROOT is the result of running the command matlabroot in your target MATLAB installation.
You may need to run rehash toolboxcache after copying the file to make sure MATLAB recognizes it. Run:
which coder.internal.ifWhileCondExtrinsic
after the copy to verify that MATLAB recognizes the file then your MEX should execute properly.

Community Treasure Hunt

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

Start Hunting!