3 10 points Write a function called myfind that will search
3. (10 points) Write a function called myfind that will search for a key in a vector and return the indices of all occurrences of the key, like the built-in find function. It will receive two arguments the vector and the key-and will return a vector of indices or the empty vector [] if the key is not found The function will be invoked as follows: lax my find (vec, key); Following is an example of correct function behavior: >> vec - randi( [5, 10], 1, 10) vec = 5 >> key = 10; >> idx = my find (vec, key) ldx - 2 >> key = 2; >> idx = my find (vec, key) 10 10 7 5 7 10 10 3 10 Empty matrix: 1-by-0 Do not use the in-built find function.
Solution
A function is a group of statements and it specified for particular task to perform. In this function myfind is the name of the function. And save it as a myfind.m
If the user enter wrong input throws an error message.
myfind.m:
function idx = myfind(vec, key);
if ~isvector(vec)
error(\'Input must be a vector\')
end
