Code covered by the BSD License  

Highlights from
isleap.m

Be the first to rate this file! 2 Downloads (last 30 days) File Size: 1.36 KB File ID: #31778

isleap.m

by Isaac Mancero Mosquera

 

13 Jun 2011 (Updated 15 Jun 2011)

This file test if a given year is a normal year or a leap year.

| Watch this File

File Information
Description

A script to assess if a given year (in the Gregorian Calendar system) is a leap year or not.

 It returns 0 if is not a leap year,
 it returns 1 if it is a leap year.

Examples:

>> isleap(1900)

ans =

     0

>> A = [1200 1538 2001 ; 816 1900 1908 ; 2000 2004 2011]

A =

        1200 1538 2001
         816 1900 1908
        2000 2004 2011

>> isleap(A)

ans =

     1 0 0
     1 0 1
     1 1 0

It looks at the remainder of the division, if the year is divisible by 4, 100 and 400 and makes the decision according to it. (For a year ending in 00 is not a leap year unless is divisible for 400 too).

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
13 Jun 2011 Jan Simon

There is absolutely no reason to clear "mod" inside a function. Please read the documentation about the difference between "scripts" and "functions".
You can simplify the algorithm: ~mod(Ym 4) & (mod(Y, 100) | ~mod(Y, 400))
An older submission, which checks the inputs also: http://www.mathworks.com/matlabcentral/fileexchange/14172-isleap-function

15 Jun 2011 Isaac Mancero Mosquera

To Jan Simon: You are right. I've deleted that unnecessary line. I made the error during the testing stage when it was still not written as a function.

On a different note, I couldn't find that other script you mentioned before, and I was actually needing one. Indeed, I decided to write this script because of that.

To all Users: this is a simple script, it's not checking if you are entering a complex, a real or a transfinite number. OTOH no citation is needed if you use this file.

15 Jun 2011 Isaac Mancero Mosquera

And sorry I'm freely using the word "script", my shame, I'll try to correct that soon.

Please login to add a comment or rating.
Updates
15 Jun 2011

I deleted unnecessary code, now it's a one line code.

Tag Activity for this File
Tag Applied By Date/Time
time Isaac Mancero Mosquera 13 Jun 2011 16:08:40
leap year Isaac Mancero Mosquera 13 Jun 2011 16:08:40

Contact us at files@mathworks.com