using testtype to check odd or even numbers

조회 수: 4 (최근 30일)
Harry
Harry 2013년 6월 28일
In my code I try to use an 'if' operator to check whether a number is odd or even, so the code knows whether to proceed. So something like this:
if testtype(j, Type::Odd) = TRUE
statements
end
But that just gives the error:
Unexpected MATLAB operator.
  댓글 수: 1
Iain
Iain 2013년 6월 28일
편집: Iain 2013년 6월 28일
:: is an unexpected matlab operator.
= should be ==, but if testtype returns true, you don't need to check that it is true.
I haven't used testtype, but I suspect that Type::Odd should be 'Type::Odd'

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 6월 28일
편집: Andrei Bobrov 2013년 6월 28일
if rem(jj,2) == 1 % odd
statements
elseif rem(jj,2) == 0 % even
statements
end
or
if rem(jj,2) % odd
statements
else % even
statements
end

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by