Passing function with parameters to another function

5 visualizaciones (últimos 30 días)
Mazin Mustafa
Mazin Mustafa el 17 de Oct. de 2017
Comentada: KSSV el 1 de Jul. de 2020
Hi,
I am trying to create a function that accepts another function with its own parameters e.g. Func1(@(x)Func2(x,para1,para2,...etc)) Is this possible in Matlab? If yes, how?
  2 comentarios
Mazin Mustafa
Mazin Mustafa el 21 de Oct. de 2017
I actually found the solution for this. just using the function handle inside the body of the function.

Iniciar sesión para comentar.

Respuestas (1)

KSSV
KSSV el 17 de Oct. de 2017
f1 = @(x,y) x(y) ;
f2 = @(y) sin(y) ;
f1(f2,pi/2)
  3 comentarios
Amjith Shaheer
Amjith Shaheer el 1 de Jul. de 2020

Why do u have to put a dot in x.^2 + a;.I am new to Matlab

KSSV
KSSV el 1 de Jul. de 2020
If x is an array to get element by element square, you have to put . i.e .^

Iniciar sesión para comentar.

Categorías

Más información sobre Programming 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