Is it possible to assign the constant value of a function handle to a variable?
Show older comments
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(@())?
Accepted Answer
More Answers (1)
Guillaume
on 19 Feb 2019
You don't need to use feval to invoke a function handle with no inputs, just use some empty brackets to make it clear you want to call it and not just copy the handle:
f = @() 0.5;
n = f()
f = @() 0.5;
g = @(x) x;
>> nargin(f)
ans =
0
>> nargin(g)
ans =
1
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!