Hi, how do I cause the following code to recognize that 92 for q and 92 for v are both passing scores, right now it returns false.

1 回表示 (過去 30 日間)
function tf = eligible( v,q )
%ELIGIBLE Summary of this function goes here
% Detailed explanation goes here
tf ='false';
avg = (v+q)/2;
if avg >=92
if v>88 && q>88
tf ='true';
end
end
end
Hi, how do I cause the following code to recognize that 92 for q and 92 for v are both passing scores, right now it returns false but it should return true for 92 for q and v
  2 件のコメント
DJ V
DJ V 2016 年 11 月 25 日
編集済み: DJ V 2016 年 11 月 25 日
function tf = eligible( v,q )
%ELIGIBLE Summary of this function goes here \
% Detailed explanation goes here
tf ='false';
avg = (v+q)/2;
if avg >=92
if v>88 && q>88
tf ='true';
end
end
end
Here is the code.
dpb
dpb 2016 年 11 月 25 日
>> eligible(92,92)
ans =
true
>>
seems to work as expected here. Perhaps you've not clear ed an earlier edit that doesn't work correctly from memory? Or the copy you're executing isn't the same as this one...try
which eligible % to see who's actually the one being found.

サインインしてコメントする。

回答 (2 件)

Image Analyst
Image Analyst 2016 年 11 月 25 日
Don't put quotes around true and false. That's setting them equal to character arrays, which you don't want. You want the boolean/logical values.
  2 件のコメント
dpb
dpb 2016 年 11 月 25 日
Good point; mayhaps that's the issue, not the logic as I read it. If his test were
if elgible(92,92)
dosomething
else
somethingnottheabovesay
end
he'd always get the else clause despite seeing 'true' as the output...

サインインしてコメントする。


Walter Roberson
Walter Roberson 2016 年 11 月 25 日
Are you certain that the values you are passing in are exactly 92? If they are exactly 92, then the way you calculate the average and compare that to 92 should work, but if the values are even one significant bit less than 92, then even though they would look like 92 when displayed, their average would be less than 92 and so the comparison you used.
n92 = 92 * (1-eps);
>> (n92+n92)/2 - 92
ans =
-1.4210854715202e-14

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by