Passing function with parameters to another function

7 Ansichten (letzte 30 Tage)
Mazin Mustafa
Mazin Mustafa am 17 Okt. 2017
Kommentiert: KSSV am 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?

Antworten (1)

KSSV
KSSV am 17 Okt. 2017
f1 = @(x,y) x(y) ;
f2 = @(y) sin(y) ;
f1(f2,pi/2)
  3 Kommentare
Amjith Shaheer
Amjith Shaheer am 1 Jul. 2020

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

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by