multiple functions within one script
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nora Al Allaf
am 4 Okt. 2020
Beantwortet: Matteo Lo Preti
am 4 Okt. 2020
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);
0 Kommentare
Akzeptierte Antwort
Matteo Lo Preti
am 4 Okt. 2020
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!