How to Test for Odd or Even Numbers in "MATLAB"

Written by josh infiesto
  • Share
  • Tweet
  • Share
  • Email

MATLAB is a high-level programming language that does not require managing memory details. MATLAB is used mostly for technical and scientific computing and is an alternative to more traditional languages, such as C or FORTRAN, when the speed of the final code isn't an issue. MATLAB provides ample tools for performing mathematical operations. Determining whether a number is even or odd can be accomplished in a few lines of code.

Skill level:
Easy

Other People Are Reading

Things you need

  • MATLAB installation

Show MoreHide

Instructions

  1. 1

    Open MATLAB by navigating to "Start-> All Programs-> MATLAB."

  2. 2

    Enter the following code into the MATLAB window:

    if mod(x,2) == 0

    %number is even

    else

    %number is odd

    end

    This code uses the "Modulus" or "Remainder" operator to test if a number is even or odd. If a number is divided by two and the remainder is zero, then the number is even. Otherwise, it is odd.

  3. 3

    Click the "Run" button in the editor to run the code.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.