MATLAB Answers

Passing function with parameters to another function

115 views (last 30 days)
Mazin Mustafa
Mazin Mustafa on 17 Oct 2017
Commented: KSSV on 1 Jul 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?

Answers (1)

KSSV
KSSV on 17 Oct 2017
f1 = @(x,y) x(y) ;
f2 = @(y) sin(y) ;
f1(f2,pi/2)
  3 Comments
KSSV
KSSV on 1 Jul 2020
If x is an array to get element by element square, you have to put . i.e .^

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!