is:Conversion to logical form function_handle is not possible.
6 views (last 30 days)
Show older comments
Tara Behmanesh
on 10 May 2020
Edited: Walter Roberson
on 10 May 2020
Hi I want to do a comparison with function handle. For example : Fun2=@(x) (4*x+1) While @(x)Fun2(x) >3 do something
The error is:Conversion to logical form function_handle is not possible. Thank a lot
0 Comments
Accepted Answer
Walter Roberson
on 10 May 2020
while Fun2(x) > 3
and be sure to update x inside the loop
2 Comments
Walter Roberson
on 10 May 2020
Edited: Walter Roberson
on 10 May 2020
The message is correct. You do not define a or b before you try to use them in
while fun2(e,a,b)>10^(-6)||fun2(e,a,b)<-10^(-6)
Reminder: when you use
fun1=@(a,b)(b-a)./2;
then that does not define variables a or b: it defines only fun1 and it defines fun1 as being an anonymous function that accepts two positional parameters that for convenience are referred to as a and b.
fun1=@(a,b)(b-a)./2;
is coded sort of like
struct( 'formula', #(_Parameter{2}-_Parameter{1})./2)# , 'ParameterNames', {'a', 'b'})
in the sense that the execution of the code depends only on parameter position and the names of the parameters are (nearly) only used for display purposes.
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB 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!