Page 1 of 1

Could you help me modify this MATLAB function so that it assigns random birthdays to people in an increasingly large gro

Posted: Mon May 09, 2022 6:12 am
by answerhappygod
Could you help me modify this MATLAB function so that it assigns
random birthdays to people in
an increasingly large group of people (starting with a group size
of 2 people and ending
with a group size of 365) and also generate whole numbers from 1 to
365 to represent each day. rather than the day/month format.
function dates = Myfunction(n)

dates=[];

for count = 1:n

random_month = randi([1 12], 1,1); % generate a random month 1 to
12
month = random_month(1,1);
if (month == 4 || month == 6 || month==9 || month==11 )
day = randi([1 30], 1,1); % there are 30 days
else if month==2
day = randi([1 28], 1,1); % there are 28 days
else
day = randi([1 31], 1,1); % there are 31 days
end
dates = [dates; [month,day]];

end

end