필터 지우기
필터 지우기

multiple functions within one script

조회 수: 2 (최근 30일)
Nora Al Allaf
Nora Al Allaf 2020년 10월 4일
답변: Matteo Lo Preti 2020년 10월 4일
Hello :)
I'm trying to use a function inside another one
min_bisect is the first one and kastbana_5(x) is the second
[10,14], 1e-5 are just inputs built within min_bisect, 10 and 14 should be used as inputs in kastbana_5 but that's written in the min_bisect script
any idea how to make this work?
z = min_bisect(kastbana_5(x), [10,14], 1e-5);
tried this one: can't get an answer here either
z = min_bisect(@(x)kastbana_5(x), [10,14], 1e-5);

채택된 답변

Matteo Lo Preti
Matteo Lo Preti 2020년 10월 4일
Hi Nora,
You can have a function as input of another one, like this out = min_bisect(fun, a, b)
In the main call, use the pass it like a function handle @kastbana_5
Here you have a sample code:
z = min_bisect(@kastbana_5, 5, 5);
function out = min_bisect(fun, a, b)
x = a+b;
out = fun(x);
end
function y = kastbana_5(x)
y = x^2;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by