multiple functions within one script
5 views (last 30 days)
Show older comments
Nora Al Allaf
on 4 Oct 2020
Answered: Matteo Lo Preti
on 4 Oct 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 Comments
Accepted Answer
Matteo Lo Preti
on 4 Oct 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 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!