Main Content

Algorithm Design Basics

Algorithm design considerations for code generation, behavior of generated code

Generating code from MATLAB® algorithms allows you to design, implement, and test software completely within the MATLAB workspace. You can:

  • Verify that your algorithms are suitable for code generation

  • Generate efficient, readable, and compact C/C++ code automatically, eliminating manually translation and minimizing the risk of introducing errors in the code.

  • Modify your design in MATLAB code to take into account the specific requirements of desktop and embedded applications, such as data type management, memory use, and speed.

  • Test the generated code and easily verify that your modified algorithms are functionally equivalent to your original MATLAB algorithms.

  • Generate MEX functions to accelerate MATLAB algorithms or speed up fixed-point MATLAB code.

  • Generate hardware description language (HDL) from MATLAB code.


coder.allowpcodeControl code generation from P-code files
coder.cevalCall C/C++ function from generated code
coder.cincludeInclude header file in generated code
coder.cstructnameName C structure type in generated code
coder.extrinsicDeclare function as extrinsic and execute it in MATLAB
coder.inlineControl inlining of current function in generated code
coder.inlineCallInline called function in generated code (Since R2024a)
coder.loadLoad compile-time constants from MAT-file or ASCII file
coder.nonInlineCallPrevent inlining of called function in generated code (Since R2024a)
coder.nullcopyDeclare uninitialized variables in code generation
coder.opaqueDeclare variable in generated code
coder.refIndicate data to pass by reference
coder.screenerDetermine if function is suitable for code generation
coder.rrefIndicate read-only data to pass by reference
coder.targetDetermine if code generation target is specified target
coder.unrollUnroll for-loop by making a copy of the loop body for each loop iteration
coder.varsizeDeclare variable-size data
coder.wrefIndicate write-only data to pass by reference
coder.updateBuildInfoUpdate build information object RTW.BuildInfo


coder.ExternalDependencyInterface to external code
coder.BuildConfigBuild context during code generation



Unknown Output Type for coder.ceval

Define the output type for external C/C++ function calls.