Respuesta :
Answer:
The MATLAB code is given below with appropriate comments
Explanation:
%Define the function.
function correctGuess = EvaluateGuesses(myNumber,userGuess)
%Compute the length.
l = length(userGuess);
%Create an array.
correctGuess = zeros(1, l);
%Begin the loop.
for k = 1: l
%Check the condition.
if myNumber == userGuess(k)
%Update the array correctGuess.
correctGuess(k) = 1;
%End of if.
end
%End of the function.
end
%Call the function.
EvaluateGuesses(3, [3, 4, 5])
Answer:
correctGuess = (myNumber == userGuess);
Explanation:
All you have to do is use the logical operator "==" to signify a relationship between myNumber and userGuess. Whenever the value of myNumber is equal to userGuess, MATLAB will input a "1" into the logical array. It will input a "0" when myNumber does NOT equal userGuess.
Example problem for EvaluateGuesses(3, [3, 4, 5])
correctGuess = (myNumber == userGuess);
The program checks for when 3 is equal to any number in the array userGuess. 3 only equals the first value, so the result is [1, 0, 0].
Therefore, the answer is correctGuess = (myNumber == userGuess);
(This is much simpler than what the other user said... this is most likely what your homework expects you to answer with.)