Error when generating code using MATLAB Coder for function containing "fread"

When I try to generate code using MATLAB Coder for a function "testCode.m" (attached), I receive an error that says -'function call failed'. This error message occurs for all lines containing the "fread" function. Why do I get this error message? 
NOTE - I have unchecked the 'Enable Variable Sizing' option because I want my code to run faster. When the option was checked, I received no errors.

 Accepted Answer

The error you are observing is due to the presence of "fread" in the MATLAB function you are trying to generate code for. The "fread" command requires variable sizing by default; therefore, disabling variable sizing in the settings will lead to the error you observe. To eliminate the errors, the 'Enable Variable Sizing' option needs to be checked in the memory settings of MATLAB Coder.
Please note that the above setting will result in the "emxEnsureCapacity" function being called in the generated code, as this is MATLAB Coder's way of dealing with variable sized arrays that have no upper bounds. In case you are working with fixed size arrays and would like to prevent calls to "emxEnsure Capacity", in the memory settings, please change the 'Dynamic Memory Allocation' option from 'For all variable sized arrays' to 'Never'. This will result in faster run times for the generated code.

More Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Release

R2016a

Community Treasure Hunt

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

Start Hunting!