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.

 Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 24 de Sept. de 2026 a las 0:00
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.

Más respuestas (0)

Categorías

Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.

Productos

Versión

R2016a

Preguntada:

el 24 de Sept. de 2026 a las 0:00

Respondida:

el 24 de Sept. de 2026 a las 15:42

Community Treasure Hunt

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

Start Hunting!

Translated by