Rank: 3654 based on 33 downloads (last 30 days) and 1 file submitted
photo

Ulf Carlberg

E-mail

Personal Profile:

 

Watch this Author's files

 

Files Posted by Ulf Carlberg
Updated   File Tags Downloads
(last 30 days)
Comments Rating
29 May 2011 Functions that checks if a number is odd or even Determine if a number is odd or even. Works with floats and integers. Error checking. Author: Ulf Carlberg odd, even, isodd, iseven, rem, mod 33 8
  • 5.0
5.0 | 2 ratings
Comments and Ratings by Ulf Carlberg View all
Updated File Comments Rating
31 May 2011 isodd: a pedestrian parity checker ISODD returns TRUE for integers of any numeric MATLAB class that are not evenly divisible by 2 Author: us

Another thing that confuses me:
>> [a,b]=isodd(1:5)
a =
1 0 1 0 1
b =
1 0 1 0 1
Shouldn't "b" be all ones in this case?

31 May 2011 Functions that checks if a number is odd or even Determine if a number is odd or even. Works with floats and integers. Error checking. Author: Ulf Carlberg

A found a few bugs and improved a few things from John D'Errico's suggestions. The new version must be approved first, within a few hours I hope.

31 May 2011 Functions that checks if a number is odd or even Determine if a number is odd or even. Works with floats and integers. Error checking. Author: Ulf Carlberg

Hi Darren,

The submission in your first link might be an alternative depending on what you want, it's a little different from my submission. The second link does not check the input and you might as well use mod(x, 2) in my opinion.

31 May 2011 Functions that checks if a number is odd or even Determine if a number is odd or even. Works with floats and integers. Error checking. Author: Ulf Carlberg

Hi Oleg,

It can be more complicated if you want errors to be raised on input where it is not possible to determine if a number is odd or even isodd(1e30) for example.

31 May 2011 isodd: a pedestrian parity checker ISODD returns TRUE for integers of any numeric MATLAB class that are not evenly divisible by 2 Author: us

I found a bug:
>> x=int8(-128)
x =
-128
>> isodd(x)
ans =
1
because abs() will round the result to fit in int8, so abs(x)=127. Same for all "weird numbers" in two complement form intN(-2^(N-1)).

Comments and Ratings on Ulf Carlberg's Files View all
Updated File Comment by Comments Rating
01 Jun 2011 Functions that checks if a number is odd or even Determine if a number is odd or even. Works with floats and integers. Error checking. Author: Ulf Carlberg John D'Errico

Think of the comments on your files as a peer review of your code. In the end, your code is now better than it was when you first submitted it.

31 May 2011 Functions that checks if a number is odd or even Determine if a number is odd or even. Works with floats and integers. Error checking. Author: Ulf Carlberg Ulf Carlberg

A found a few bugs and improved a few things from John D'Errico's suggestions. The new version must be approved first, within a few hours I hope.

31 May 2011 Functions that checks if a number is odd or even Determine if a number is odd or even. Works with floats and integers. Error checking. Author: Ulf Carlberg Ulf Carlberg

Hi Darren,

The submission in your first link might be an alternative depending on what you want, it's a little different from my submission. The second link does not check the input and you might as well use mod(x, 2) in my opinion.

31 May 2011 Functions that checks if a number is odd or even Determine if a number is odd or even. Works with floats and integers. Error checking. Author: Ulf Carlberg Ulf Carlberg

Hi Oleg,

It can be more complicated if you want errors to be raised on input where it is not possible to determine if a number is odd or even isodd(1e30) for example.

30 May 2011 Functions that checks if a number is odd or even Determine if a number is odd or even. Works with floats and integers. Error checking. Author: Ulf Carlberg Darren Rowland

Hi Ulf,

I notice that there are a couple of other FEX files called "isodd".
http://www.mathworks.com/matlabcentral/fileexchange/24278
http://www.mathworks.com/matlabcentral/fileexchange/2006

Do you know of any differences between these files and yours?
Darren

Contact us