hi,
i was asked to write a simple function for home work :
this was my code:
function [admit]=eligible(v,q)
avg=(v+q)/2;
if (avg>=92) && (v>88) && (q>88)
admit=1;
else
admit=0;
end
end
and i don't understand why i got this error message :
please advise what is the problem.
thank's

 채택된 답변

madhan ravi
madhan ravi 2020년 5월 30일

0 개 추천

Replace 1 with ~0 and 0 with ~1.

댓글 수: 6

madhan ravi
madhan ravi 2020년 5월 30일
The problem is your data type is double rather it should be logical meaning it should indicate true or false , something like yes or no. The code should say either true or false it does not matter if it is 1 or 0.
doc logical
doron kra
doron kra 2020년 5월 30일
Thanks mate!
that solved the problem :-)
Image Analyst
Image Analyst 2020년 5월 31일
Then why didn't you click the "Accept this answer" link to award madhan reputation points, and let others know it's already been solved?
doron kra
doron kra 2020년 5월 31일
i didn't do it Intentionally ,i've clicked the "Accept this answer" now. maybe you should make the process more clear for new users.
Stephen23
Stephen23 2020년 5월 31일
Rather than obfuscated code using negations of numeric values, it is clearer to write true and false:, i.e.:
admit = true;
Note that you can trivially replace the entire if-else-end statement:
admit = (avg>=92) && (v>88) && (q>88);
doron kra
doron kra 2020년 5월 31일
Wow, this is very elegant !
thanks for showing me that :-)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

질문:

2020년 5월 30일

댓글:

2020년 5월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by