33% found this document useful (3 votes)
1K views

Lessson 5 Wrap Up

matlab

Uploaded by

Bijay Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
33% found this document useful (3 votes)
1K views

Lessson 5 Wrap Up

matlab

Uploaded by

Bijay Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 3
srear2ot9 Mathworks Learning Tool Lesson 5 Wrap-up Write a function called valid_date that takes three positive integer scalar inputs year, month, day. If these three represent a valid date, retum a logical true, otherwise false. The name of the output argument is valid. If any of the inputs is not a positive integer scalar, return false as well. Note that every year that is exactly divisible by 4 is a leap year, except for years that are exactly divisible by 100, However, years that are exactly divisible by 400 are also leap years. For example, the year 1900 was not leap year, but the year 2000 was. Note that your solution must not contain any of the date related built-in MATLAB functions. Function C Reset B& MATLAB Documentation (https://www.mathworks.com/help/) 3 function valid = valid_date(year,month, day) 2 if isscalar(year)==true && year>@ && isscalar(month)==true && month>® && 12>=month 3 4 if (mod(year,4) == @ && mod(year, 100)~= @ || mod(year,400)==0) checks if it's 5 isleap=true; 6 else 7 isleap=false; 8 end ° if any(month == [4,6,9,11]) && day<=3@ || any(month == [1,3,5,7,8,10,12]) 8& da 10 valid = true; pas elseif isleap == true && month == 2 && day<-29 || isleap -- false && month 12 valid=true; B else a valid=false; 15 end 16 | else wy valid=false; 38 end 19 28 end Code to call your function C Reset 1 hitps:learninglooL mathworks.corviaunch 18 arzazot9 Mathworks Learning Tool ? valid = valid_date(2018,4,1) > valid = valid_date(2e18,4,31) Output valid = logical 1 valid = logical e Assessment: All Tests Passed > Run Function | @ Submit e © Various inputs @ Non-scalar @ The last day of every month © Random leap years @ Random non-leap years @ Random dates hitps:learninglooL mathworks.corviaunch 23 srear2ot9 hitps:learninglooL mathworks.corviaunch MathWorks Learning Tool a3

You might also like