MATLAB: Is it possible to assign the constant value of a function handle to a variable

functionMATLAB

Hello,
My program can sometimes generate this function handle:
g = @() 1.0
Or generally: g = @() c , c: constant
Is it possible to transfer that constant into a variable B, so that B = c?
Thanks.
Edit: Is it possible to check whether a function_handle has no inputs(@())?

Best Answer

If you want to use the feval (link) function, yes:
g = @() 1;
B = feval(g)
producing:
B =
1
There may also be other ways to evaluate a function that does not accept an argument.