Function handle is a common data type of Matlab.
The function handle is created using @ or str2func () to generate the function handle.
>>% Create a cos () function handle >>%method 1: [email protected]> [email protected] hcos = @ cos >>%method 2: FH = str2func ('cos ')> FH = str2func ('cos') FH = @ CoS> Functions (hcos) % use functions to detect ans = function: 'Cos 'Type: 'simple' file: ''> Functions (FH) % use functions to detect it ans = function: 'cos 'Type: 'simple' file: ''> ISA (hcos, 'function _ handle') % use ISA to detect ans = 1> ISA (FH, 'function _ handle ') % use ISA to detect ans = 1> whos % view all handle information name size bytes class attributes FH 1x1 16 function_handle hcos 1x1 16 function_handleExample:
> [Email protected] (x, y) (x ^ y) % defines the function handle. The first bracket is the variable, and the second bracket is the expression SQRT = @ (x, y) (x ^ y)> A = SQRT () % direct call to implement computation A = 32
MATLAB basics -------- function handle