Assign function handle to existing Function object
setHandle(F,@fun)
F.setHandle(@fun)
F |
Existing Function object which function we want to overwrite.
Class: Function |
F |
Representation of the new function given as function_handle class.
Class: function_handle |
F |
Modified Function objects. Class: Function |
k=2;Then we can construct the object with this value of the parameter as
F1 = Function(@(x) k*x)
Function: @(x)k*xEvaluating this function will always take
feval(F1.Handle,1)
ans = 2Changing the value of
k=3;
feval(F1.Handle,1)
ans = 2If the value of
F2 = Function(@(k,x) k*x)
Function: @(k,x)k*xEvaluation of this function requires two arguments, i.e.
feval(F2.Handle,2,1)
ans = 2Another option is to store the parameter
F3 = Function([],struct('k',2))
Empty FunctionNow we can assign the function handle with the reference to the parameter
F3.setHandle(@(x) F3.Data.k*x)
Function: @(x)F3.Data.k*xIf we change the value of the parameter
F3.Data.k = 3;this new value will be taken for evaluation.
feval(F3.Handle,1)
ans = 3
F = Function([], struct('a',10.4,'b',-0.56))
Empty FunctionSecondly, set the handle pointing to the parameters stored inside Data property
F.setHandle(@(x)F.Data.a*sin(F.Data.b*x))
Function: @(x)F.Data.a*sin(F.Data.b*x)The values of the parameters
F.Data.a = 12.78; F.Data.b = -0.93
Function: @(x)F.Data.a*sin(F.Data.b*x)
F(2,1) = Function
Array of 2 Functions.Assign the data
F(1).Data = struct('a',-1,'b',2);
F(1).setHandle(@(x)F(1).Data.a*sin(F(1).Data.b*x));
F(2).Data = struct('a',-3,'b',4);
F(2).setHandle(@(x)F(2).Data.a*sin(F(2).Data.b*x));
F(2) = Function
Array of 2 Functions.Assign two function handles must be done in a cell
F.setHandle({@(x)x, @(x)x^2})
Array of 2 Functions.
◀ | mpt | isemptyfunction | ▶ |
© 2010-2013 Martin Herceg: ETH Zurich, herceg@control.ee.ethz.ch