MATLAB: Function handle as function input

functionfunction handleinput

Hello there, I have a function handle, for example f = @(x) x.^2 and I want to use this as a function input, something like (just schematic):
function scalar = fct(f(x));
scalar = int(@(x) f(x).*x^2);
end
Is that possible? Greets and thanks!

Best Answer

Inside such a wrapper, I highly doubt that. But in principle it should be possible to do what you want. I haven't tested this code, but I think this should work. (After a peek at the doc for int, I suspect this would error, but the principle should hold, after all, f is just a variable, even if it is a weird variable because it is an anonymous function)
function scalar=fct(f)
temp=@(x) f(x).*x.^2;
scalar=int(temp);
end