MATLAB Answers

Passing function with parameters to another function

조회 수: 166(최근 30일)
Mazin Mustafa
Mazin Mustafa 17 Oct 2017
댓글: KSSV 1 Jul 2020
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

Mazin Mustafa
Mazin Mustafa 21 Oct 2017
I actually found the solution for this. just using the function handle inside the body of the function.

댓글을 달려면 로그인하십시오.


KSSV 17 Oct 2017
f1 = @(x,y) x(y) ;
f2 = @(y) sin(y) ;

  댓글 수: 3

Mazin Mustafa
Mazin Mustafa 21 Oct 2017
This helps but the answer is: f1 = @(x,a) x.^2 + a; f2 = @(func,b) 2*func(10) - b; Call f2 ( @(x) f1(func,a),b)
Amjith Shaheer
Amjith Shaheer 1 Jul 2020

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

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

댓글을 달려면 로그인하십시오.


Community Treasure Hunt

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

Start Hunting!

Translated by