inputname
Variable name of function input
Syntax
Description
Examples
Input Arguments
Output Arguments
Tips
inputnameis 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
inputnamein the critical path of code or to obtain variable names to be used with commands such aseval,evalin, andassignin. This use ofinputnamecan lead to code that is difficult to maintain.inputnamereturns an error if it is called inside an overloadedsubsref,subsasgn,subsindex,numArgumentsFromSubscript,numel, or property set or get method.inputnamecannot get the names of arguments that are contained in a forwarded indexing operation. Instead, it returns an empty string.If the function that calls
inputnameis not called from a MATLAB code file,inputnamewalks up the stack until it finds a call from MATLAB code and returns the names it finds there. For example, this behavior occurs ifinputnameis called from a built-in function or a MEX function.Consider the following code in which the built-in
arrayfunfunction callsinputnamevia a function handle.fn=@(x) inputname(x); a=1:4; arrayfun(fn,a,'uniformoutput',false)ans = 'fn' 'a' '' ''The
inputnamefunction walks up the stack until it finds a call from MATLAB code. In this case, the MATLAB code is the base workspace, andinputnamereturns variable names from the base workspace
Extended Capabilities
Version History
Introduced before R2006a