How to use one function handle to generate function handles returning different values?
2 views (last 30 days)
Show older comments
For example, here is my function:
function [ fy, fz ] = funtest( x,a )
fy = x + 1 + a;
fz = x + 1 + a + 2*a;
end
We can see fy and fz are similar, so I do not want to write two functions for each of them respectively. I do not use the function to get function value. I want to get function handles. Such as, in command window, when I type in
a = 3; f1 = @(x)funtest(x,a)
something like this, and I have a function handle for fy. MeanWhile maybe
f2 = @(x)funtest(x,b)...
having a little bit modification for fz.
I tried
f1 = @(x)funtest(x,a)(1)
for fy, and get an error "Error: ()-indexing must appear last in an index expression." And
[f1, f2] = @(x)funtest(x,a)
gets an error "Error: Only functions can return multiple values." .
Any suggestion is appreciate. Have a beautiful day!
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!