함수 정의
코드 생성에 사용할 목적으로 MATLAB® 함수를 만들 때 특별히 고려해야 할 사항이 있습니다. 이러한 고려 사항에는 varargin과 varargout, 재귀 함수, 익명 함수, 중첩 함수를 사용할 때의 특정 제한 사항이 포함됩니다. 코드 생성기는 MATLAB 재귀 함수의 코드를 생성하기 위해 컴파일타임 재귀 또는 런타임 재귀를 사용합니다. 코드 생성기는 효율적인 C/C++ 코드를 생성하기 위해 함수 특수화라고 하는 여러 버전의 함수를 생성하는 경우가 있습니다. 경우에 따라 coder.ignoreSize와 coder.ignoreConst를 사용하여 코드 생성기에서 함수 특수화를 생성하지 못하게 할 수 있습니다. MEX 함수를 생성하는 동안 MATLAB 코드에 있는 특정 함수에 대한 코드 생성을 건너뛰고 대신 MATLAB 엔진을 사용하여 호출을 실행할 수 있습니다. 이렇게 하려면 coder.extrinsic 구문을 사용하십시오.
함수
| coder.extrinsic | 함수를 외재적 함수로 선언하고 MATLAB에서 실행 | 
| coder.ignoreConst | 표현식의 상수 값을 사용한 함수 특수화 금지 | 
| coder.ignoreSize | Prevent code generator from creating function specializations for constant-size expressions | 
| coder.mustBeComplex | Validate that value lies on the complex plane (R2023b 이후) | 
| coder.mustBeConst | Validate that value is a compile-time constant (R2023b 이후) | 
| coder.noImplicitExpansionInFunction | Disable implicit expansion within the specified function in the generated code (R2021b 이후) | 
| coder.sameSizeBinaryOp | Apply element-wise binary operations without implicit expansion (R2021b 이후) | 
| coder.specifyAsGPU | Specify that value is a GPU input to an entry-point function for GPU code generation (R2023b 이후) | 
도움말 항목
- 컴파일 지시문 %#codegenMATLAB 함수가 코드 생성을 위한 것임을 표시합니다. 
- Generate Code with Implicit Expansion EnabledThe code generator introduces modifications in the generated code to accomplish implicit expansion. 
- Optimize Implicit Expansion in Generated CodeImplicit expansion in the generated code is enabled by default. 
- 가변 길이 인수 목록에 대한 코드 생성varargin및varargout에 대한 코드를 생성합니다.
- Generate Code for arguments Block That Validates Input and Output ArgumentsGenerate code for MATLAB code that constrains class, size, and other aspects of function input and output values. 
- Code Generation for Recursive FunctionsUse recursive functions in MATLAB code that is intended for code generation. 
- Force Code Generator to Use Run-Time RecursionRewrite your MATLAB code so that the code generator uses run-time recursion instead of compile-time recursion. 
- 익명 함수에 대한 코드 생성코드 생성을 위한 MATLAB 코드에 익명 함수를 사용합니다. 
- Code Generation for Nested FunctionsUse nested functions in MATLAB code intended for code generation. 
- Resolution of Function Calls for Code GenerationThe code generator uses precedence rules to resolve function calls. 
- Resolution of File Types on Code Generation PathThe code generator uses precedence rules to resolve file types. 
- MATLAB Engine을 사용하여 생성 코드에서 함수 호출 실행하기함수가 코드 생성을 지원하지 않는 경우 MATLAB에서 실행할 수 있도록 함수를 외재적 함수로 선언합니다. 
문제 해결
for 루프에서 varargin 또는 varargout에 대한 인덱스가 상수가 아닌 경우
코드 생성기가 varargin 또는 varargout에 대한 인덱스 값을 확인할 수 없는 경우 루프 풀기를 강제로 실행합니다.
Avoid Duplicate Functions in Generated Code
Reduce the occurrence of duplicate functions in the generated code.
Output Variable Must Be Assigned Before Run-Time Recursive Call
Troubleshoot output variable assignment for run-time recursion.
Compile-Time Recursion Limit Reached
Troubleshoot compile-time recursion limit error.
코드 생성 중에 발생하는 크기 비호환성 오류를 해결합니다.
Resolve Issue: coder.inline("never") and coder.nonInlineCall Do Not Prevent Function Inlining
Troubleshoot instances of coder.inline('never') not
                    preventing inlining.
문제 해결: 변수를 사용하기 전에 완전히 정의해야 합니다
구조체 필드와 클래스 속성을 포함하여 변수를 사용하기 전에 변수가 정의되지 않은 경우에 발생하는 코드 생성 오류를 해결합니다.
Resolve Error: Cannot Determine the Exact Number of Iterations for a Loop
Troubleshoot error when code generator is unable to correctly determine number of loop iterations.