Main Content

함수 정의

코드 생성을 위한 함수 정의 및 호출

코드 생성에 사용할 목적으로 MATLAB® 함수를 만들 때 특별히 고려해야 할 사항이 있습니다. 이러한 고려 사항에는 vararginvarargout, 재귀 함수, 익명 함수, 중첩 함수를 사용할 때의 특정 제한 사항이 포함됩니다. 코드 생성기는 MATLAB 재귀 함수의 코드를 생성하기 위해 컴파일타임 재귀 또는 런타임 재귀를 사용합니다. 코드 생성기는 효율적인 C/C++ 코드를 생성하기 위해 함수 특수화라고 하는 여러 버전의 함수를 생성하는 경우가 있습니다. 경우에 따라 coder.ignoreConstcoder.ignoreSize를 사용하여 코드 생성기에서 함수 특수화를 생성하지 못하게 할 수 있습니다. MEX 함수를 생성하는 동안 MATLAB 코드에 있는 특정 함수에 대한 코드 생성을 건너뛰고 대신 MATLAB 엔진을 사용하여 호출을 실행할 수 있습니다. 이렇게 하려면 coder.extrinsic 구문을 사용하십시오.

함수

coder.extrinsic함수를 외재적 함수로 선언하고 MATLAB에서 실행
coder.ignoreConst표현식의 상수 값을 사용한 함수 특수화 금지
coder.ignoreSizePrevent code generator from creating function specializations for constant-size expressions (R2019b 이후)
coder.mustBeComplexValidate that value lies on the complex plane (R2023b 이후)
coder.mustBeConstValidate that value is a compile-time constant (R2023b 이후)
coder.noImplicitExpansionInFunctionDisable implicit expansion within the specified function in the generated code (R2021b 이후)
coder.sameSizeBinaryOpApply element-wise binary operations without implicit expansion (R2021b 이후)
coder.specifyAsGPUSpecify that value is a GPU input to an entry-point function for GPU code generation (R2023b 이후)

도움말 항목

문제 해결

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 Issue: Variables Must Be Fully Defined Before Use

Troubleshoot code generation errors when variables, including structure fields and class properties, are not defined before use.