I want to repeat this procedure for NT = 1e4 trials, storing the N-value for each trial in a 1e4 element array, and report the median number. how to make every iteration's length of the group gets added to the N array that I created the zeros syntax? I want just one array of NT elements at the end.
N = zeros(1,NT);
for j = 1:NT
% while loop for recycling the match of birthdays in the same week.
matchFound = 0;
k = 0; group = ceil(365*rand);
while matchFound == 0 && k <= NT
k = k + 1;
newBD = ceil(365*rand);
% if conditioning a group with birthdays in the same week.
if abs(newBD - group(k)) < 7 ...
|| abs(newBD - group(k) - 365) < 7 ...
|| abs(newBD - group(k) + 365) < 7
matchFound = 1;
fprintf('The required number of people is %i\n', length(group))
N = length(group);
end
% New Birthday groups upon each new addition of a person.
newG = [group; newBD];
group = newG;
end
end
fprintf('Median Number of People %i ', median(N))
end

 채택된 답변

James Tursa
James Tursa 2019년 7월 31일

1 개 추천

Maybe assign into elements of N with indexing:
N(j) = length(group);

댓글 수: 3

Mina Mansour
Mina Mansour 2019년 7월 31일
Where exactly do I assign N(j)?
James Tursa
James Tursa 2019년 7월 31일
I would assume the same place you are assigning it now. Just change the left hand side from N to N(j).
Mina Mansour
Mina Mansour 2019년 7월 31일
Thank You it worked!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Birthdays에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2019년 7월 31일

댓글:

2019년 7월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by