Clear Filters
Clear Filters

How to increment a variable

4 views (last 30 days)
Riven Yvet
Riven Yvet on 9 Dec 2015
Answered: Walter Roberson on 9 Dec 2015
Hi. I have a code that outputs the given day for a specific date (ANY DATE). I first calculated the sum of the month, year and day in number keys then the results is to be divided by 7 which is then proposed to an if else statements. Now Imm running the code fine when I input any dates from March 2012 to jan 2016. My problem is, every four years, leap year happens so fhere is an increase in days IN FEBRUARY. My question is how do you increment this interms of adding one per for four years, and only adding that one to the february date? I know its an increment thing but i really dont know how. Thanks

Answers (1)

Walter Roberson
Walter Roberson on 9 Dec 2015
year_is_leap_year = (YEAR >= 1583) & (YEAR < 4909) & (mod(YEAR,4) == 0) & ((mod(YEAR,400) == 0) | (mod(YEAR,100) ~= 0));
Unless, that is, you are calculating for England or any possession of England including USA, in which case the 1583 needs to be changed to 1753.
The 4909 year is the latest year by which there will need to be a correction because the current system has a year approximately 26 seconds too long.

Tags

Community Treasure Hunt

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

Start Hunting!