MATLAB: Pass ‘function handle’ to another ‘function handle’

functionfunction handlepassing functions

hello there, I have a function handle, for example: f = @(x) x.^2 and this I want to put within another function handle, to integrate the new function, so smth like this I would like to have:
int(@(x) 5*log(x).*f)
, where f is the function above. Is this possible? Greets and thanks!

Best Answer

It is definitely possible. You need to change your code a bit first:
int_fcn = @(x,fcn) 5*log(x).*fcn(x);
f = @(x) x.^2;
x = 10;
Result = int_fcn(x, f)
Result =
1.1513e+003