Applying LeapYear function into the Matlab Scipt
이전 댓글 표시
Creat a function called isLeapYear(intYear) that determines if the input year is a leap year or not. Write the main program to calculate the total days passed in a year for a given date. Prompt the user for the (integer) inputs: year, month, and day. The output is the total days passed since Jan 1st of that year excluding the input date (e.g., if the user gives 2012, 01, 23, then the output is 22). Call the function isLeapYear(intYear) to determine if the year is leap or not, if necessary.
Here's my function:
function LeapYear = isLeapYear(intYear)
a = mod(intYear,400);
b = mod(intYear,100);
c = mod(intYear,4);
LeapYear = ((a==0)||(b~=0 && c==0));
end
Here's my main code:
clear,clc
%1. Get Inputs
intYear = input('Enter Year: ');
intMonth = input('Enter Month: ');
intDay = input('Enter Day: ');
%2. Calculate days passed
if isLeapYear==0
intDaysPassed = ((((intMonth - 1)*30)+intDay) - 1);
else
strMessage = 'Please enter a valid leap year';
msgbox(strMessage)
return
end
I tried using "isLeapYear==0" but it's not working. How would I be able to define if a function is true or not in order to proceed with the process?
Thank you so much !!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Satellite Mission Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!