inputname
Variable name of function input
Syntax
Description
Examples
Input Arguments
Output Arguments
Tips
inputname
is a convenient way to communicate the name of an input variable to a function. For example, a function checks the data types of inputs and, if it finds an incorrect type, displays the name of the variable from your workspace.Avoid using
inputname
in the critical path of code or to obtain variable names to be used with commands such aseval
,evalin
, andassignin
. This use ofinputname
can lead to code that is difficult to maintain.inputname
returns an error if it is called inside an overloadedsubsref
,subsasgn
,subsindex
,numArgumentsFromSubscript
,numel
, or property set or get method.inputname
cannot get the names of arguments that are contained in a forwarded indexing operation. Instead, it returns an empty string.If the function that calls
inputname
is not called from a MATLAB code file,inputname
walks up the stack until it finds a call from MATLAB code and returns the names it finds there. For example, this behavior occurs ifinputname
is called from a built-in function or a MEX function.Consider the following code in which the built-in
arrayfun
function callsinputname
via a function handle.fn=@(x) inputname(x); a=1:4; arrayfun(fn,a,'uniformoutput',false)
ans = 'fn' 'a' '' ''
The
inputname
function walks up the stack until it finds a call from MATLAB code. In this case, the MATLAB code is the base workspace, andinputname
returns variable names from the base workspace
Extended Capabilities
Version History
Introduced before R2006a