Please create a function that returns the minimum element and its index in a numeric array singlerow vector or singlecolumn vector Name your function as findMin The input to the function can be either a row vector, a column vector, or a scalar of numeric data types otherwise the function returns a vector of NaNs NaN NaN Your function returns scalar values in the format of minval, minidx which represents the value and index of the minimum element, respectively. For example, return if input is the scalar If the array contains duplicates of the minimum element, keep only the smallest index of the minval. DO NOT return multiple indices. You are not permitted to use the builtin min or max functions. You can exploit if for or while structures to create your functions. Any algorithm or method can be used. The function header is already givfunction minval, minidx findMininput
if isscalarinput
minval input;
minidx ;
return;
end
Check if input is a vector
if isvector input
minval NaN;
minidx NaN;
return;
end
Initialize minval and minidx
minval input;
minidx ;
Iterate over the input vector
for : lengthinput
if inputi minval
minval inputi;
minidx ;
end
end
end
Code to call your function
minval, minidx findMin
Assessment: of Tests Passed
Correct output for a row vector.
Correct output for a scalar.
NaNNaN if input is not a numeric array or is of incorrect sizesen as function minval, min idx findMin input Function