In MATLAB, finish the following function find_first(array, value) which returns the index i into the array where the first occurrence of value is found. If value is not in the array, a warning is raised and the index NaN is returned.
i.e. the following should return a value of 4: find_first([2,7,1,8,2,8,1], 8)
Code is:
n = length(array);
i = 1;
while i <= n && array(i) ~= value
i = i + 1;
end
% Check if value was not found
if i > n
warning('Value was not found.');
i = NaN;
end