MATLAB: I am making a mistake(s) but I can’t catch it.

for loophomeworkMATLAB

The following table shows the height and age of some potential basketball players a team is willing to draft. Assuming the search criteria is age less than 26 and height greater than 75 inches, identify the players who meet the criteria, and use fprintf command to return the search result to the command window in the following format:
The following candidates meet the height and age requirement:
Candidate #1 is 24 years old and 79 inches tall
Candidate #4 is 23 years old and 77 inches tall
Candidate #8 is 20 years old and 77 inches tall
.
(The table have the values for age and height presented below.)
age=[24,26,18,23,27,29,21,20,26,18,22,27];
height=[79 82 72 77 78 83 73 77 76 81 79 82];
for i=1:12
n(height,age)=rand()
if (age<26 && height>75)
disp('These are the students')
elseif (age==24 && height==70)
disp('Candidate1')
elseif (age==23 && height==77)
disp('Candidate2')
else (age==20 && height==77)
disp('Candidate3')
end
end

Best Answer

Close, but try it this way:
age=[24,26,18,23,27,29,21,20,26,18,22,27];
height=[79 82 72 77 78 83 73 77 76 81 79 82];
meetCriteria = age < 26 & height > 75;
for k = 1 : length(age)
fprintf('Candidate #%d is %d years old and %d inches tall.\n', ...
k, age(k), height(k));
if meetCriteria(k)
fprintf(' Candidate #%d meets the criteria.\n', k);
else
fprintf(' Candidate #%d does not meet the criteria.\n', k);
end
end