Operator '+' is not supported for operands of type 'function_handle'.

6 visualizaciones (últimos 30 días)
JICHAO ZHANG
JICHAO ZHANG el 21 de Jun. de 2023
Respondida: 埃博拉酱 el 26 de Jun. de 2023
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

Respuestas (2)

Matt J
Matt J el 21 de Jun. de 2023
Editada: Matt J el 21 de Jun. de 2023
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)
ans = 23
  3 comentarios
Dyuman Joshi
Dyuman Joshi el 26 de Jun. de 2023
@JICHAO ZHANG please check Matt's response to your comment.

Iniciar sesión para comentar.


埃博拉酱
埃博拉酱 el 26 de Jun. de 2023
Only symbolic functions can be added directly. You may need to refer to Symbolic Math Toolbox.

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by