using testtype to check odd or even numbers

2 vues (au cours des 30 derniers jours)
Harry
Harry le 28 Juin 2013
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 commentaire
Iain
Iain le 28 Juin 2013
Modifié(e) : Iain le 28 Juin 2013
:: 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'

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 28 Juin 2013
Modifié(e) : Andrei Bobrov le 28 Juin 2013
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

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by