I'm new to Matlab and I'm trying to write custom function in matlab that would take function handle as one of its arguments. I'm getting this error all the time:
Error using subsindex
Function 'subsindex' is not defined for values of class 'function_handle'.
Trying to debug I performed following test: I run command x = fminbnd(@humps, 0.3, 1)
. I proceeded as expected - I got result x = 0.6370
.
So I created custom function called train
and I copied ALL the code of function fminbnd
to the file train.m
. The only thing that I changed is the name, so that code of functions fminbnd
and train
is now identical except for the names.
Now I run both functions with the same argument and the custom function throws error while original fminbnd
returns correct answer.
Here is the code:
>> x = fminbnd(@humps, 0.3, 1)
x =
0.6370
>> x = train(@humps, 0.3, 1)
Error using subsindex
Function 'subsindex' is not defined for values of class 'function_handle'.
Here is header of function train
(everything else is copied from fminbnd
):
function [xf,fval,exitflag,output] = train(funfcn,ax,bx,options,varargin)
Where is the problem?