coder.mfunctionname
Description
returns the name of
the function or method in whose body this function call is placed. For anonymous functions,
name
= coder.mfunctionnamename
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.
Examples
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 a
4
-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 same
4
-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:
foo
Currently running: @(~)fprintf('Currently running: %s\n',coder.mfunctionname)
Generate a MEX function for foo
.
codegen foo
Code generation successful.
Call the generated MEX function.
foo_mex
Currently running: foo/@(~)fprintf('Currently running: %s\n',coder.mfunctionname)
Output Arguments
name
— Name of the currently running function or method
character vector
Name of the function or method that called the
coder.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, |
|
|
Inside a class constructor. For example, constructor of
|
|
|
Inside an anonymous function. | Text of the anonymous function. | Concatenation of these two character vectors, separated by a forward slash character:
|
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
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)