coder.mfunctionname - Name of calling function or method - MATLAB (original) (raw)

Main Content

Name of calling function or method

Since R2021b

Syntax

Description

[name](#mw%5F8130adff-6aff-4876-b8c9-496dcf2f6299) = coder.mfunctionname returns the name of the function or method in whose body this function call is placed. For anonymous functions,name contains the function definition.

When debugging your MATLAB® code or the generated code, use this function to access the name of the currently running function or method.

example

Examples

collapse all

Access Name of Function

Use coder.mfunctionname to access the name of the currently running function.

Define the MATLAB function sumOfDeviations:

function y = sumOfDeviations(x) y = sum(x - mean(x),'all'); fprintf('%s returned the value: %f\n',coder.mfunctionname,y); end

Call sumOfDeviations with a4-by-4 input:

sumOfDeviations(magic(4));

sumOfDeviations returned the value: 0.000000

Generate a MEX function for the sumOfDeviations function. Specify the input as a 4-by-4 double.

codegen sumOfDeviations -args {zeros(4)}

Code generation successful.

Call the generated MEX function sumOfDeviations_mex with the same4-by-4 input:

sumOfDeviations_mex(magic(4));

sumOfDeviations returned the value: 0.000000

Access Text of Anonymous Function

Use coder.mfunctionname to access the text of the currently running anonymous function.

Define the MATLAB function foo that both defines and calls an anonymous function. The anonymous function calls coder.mfunctionname inside its body.

function foo z = @(~) fprintf('Currently running: %s\n',coder.mfunctionname); z(); end

Call foo at the MATLAB command line:

Currently running: @(~)fprintf('Currently running: %s\n',coder.mfunctionname)

Generate a MEX function for foo.

Code generation successful.

Call the generated MEX function.

Currently running: foo/@(~)fprintf('Currently running: %s\n',coder.mfunctionname)

Output Arguments

collapse all

name — Name of the currently running function or method

character vector

Name of the function or method that called thecoder.mfunctionname function, returned as a character vector.

In certain special cases, the output of coder.mfunctionname in the generated code might be different from MATLAB execution:

Context of calling coder.mfunctionname Output in MATLAB Output in Generated Code
Inside a method placed in a class folder (@-folder) For example, MyMethod ofMyClass. 'MyMethod' 'MyClass.MyMethod'
Inside a class constructor.For example, constructor ofMyClass. 'MyClass.MyClass' 'MyClass (constructor)'
Inside an anonymous function. Text of the anonymous function. Concatenation of these two character vectors, separated by a forward slash character:Output of coder.mfunctioname for the function enclosing the anonymous functionText of the anonymous functionSee Access Text of Anonymous Function.

Extended Capabilities

C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

See Output Arguments.

GPU Code Generation

Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Usage notes and limitations:

See Output Arguments.

Version History

Introduced in R2021b