Operator '+' is not supported for operands of type 'function_handle'.
Show older comments
I have two function handle,such as g=@(x)x+a,f=@(y)y+b
why not do '+'
h=g+f
for example
for t=1:10
h(0)=g;
h=g+t.*f
end
Answers (2)
It's a bad idea (i.e. very inefficient) to add two functions together, however, the proper way would be as follows:
g=@(x)x+1;
f=@(y)y+2;
h=@(z) g(z)+f(z);
h(10)
3 Comments
JICHAO ZHANG
on 21 Jun 2023
Matt J
on 21 Jun 2023
h=@(x,y) g(x)+f(y);
Dyuman Joshi
on 26 Jun 2023
@JICHAO ZHANG please check Matt's response to your comment.
埃博拉酱
on 26 Jun 2023
0 votes
Only symbolic functions can be added directly. You may need to refer to Symbolic Math Toolbox.
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!