is:Conversion to logical form function_handle is not possible.

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

 채택된 답변

Walter Roberson
Walter Roberson 2020년 5월 10일
while Fun2(x) > 3
and be sure to update x inside the loop

댓글 수: 2

Thanks it worked.but now another error occurs: undefined function or variable 'a'. The code is attached
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by