MATLAB: MatLab multiple functions question

helpmatlab functionmulti function

Write two functions. The first function, with its file name IsLeapYear.m, accepts a year (as a numerical input argument) and determines whether the year is a leap year. The output argument should be a Boolean variable, which should be true if the year is a leap year and false otherwise. The rules for determining leap years in the Gregorian calendar are: • All years evenly divisible by 400 are leap years. • Years evenly divisible by 100 but not by 400 are not leap years. • Years divisible by 4 but not by 100 are leap years. • All other years are not leap years.
The second function, with its file name GetLeapYears.m, generates and outputs a list of leap years. This function should have two input arguments startYear and endYear, which are used to form a sequence of years. For example, if the startYear is 2020, and the endYear is 2120, then the sequence of years would be 2020:2120 (one dimensional array). Use a loop to go through all these years to check if a certain year is a leap year using the IsLeapYear function you have written. This function should have one output argument outputting a list of leap years selected from the array of years between startYear and endYear
This a question I was given and I have written some code. My code doesn't work, and Im just trying to figure out what im missing in the code, if anyone could help direct me?
My two function scripts are here!
function IsLeapYear(Year)
%UNTITLED11 Summary of this function goes here
% Detailed explanation goes here

if rem(Year,400) == 0
TOF=1;
elseif rem(Year,4)== 0 && rem(Year,100)~= 0
TOF=1;
elseif rem(Year,100) == 0 && rem(Year,400)~=0
TOF=0;
else
TOF=0;
end
if TOF == 1
disp('True')
elseif TOF == 0
disp('False')
end
----------------------------------------------------------------------------------------------------------------------------------------
function [outputArg1] = GetLeapYears(startYear,endYear)
%UNTITLED12 Summary of this function goes here
% Detailed explanation goes here
m = endYear - startYear;
v = [startYear:1:endYear];
b = zeros(1,m);
for c = 1:m
for a = startYear:endYear
b(c) = IsLeapYear(a);
end
end
end

Best Answer

The instructions ask for: "The output argument should be a Boolean variable". Your function IsLeapYear does not reply anything yet. This can be done by:
function T = IsLeapYear(Year)
T = ~mod(Year, 4) & (mod(Year, 100) | ~mod(Year, 400))
end
In the 2nd function think twice if this is correct:
m = endYear - startYear;
If endYear equals startYear, m is 0, but it should be 1.
You create v already, but do not use it, but it is a good solution:
for c = 1:m
b(c) = IsLeapYear(v(c));
end
Now b is a logical vector, which is TRUE for the leap years. You can use it directly to reply the leap years only:
outputArg1 = v(b);