Digital Signal Processing Reference
In-Depth Information
%
function min_val = mymin(x)
% Get an initial guess for the min
min_val = x(1);
% Now go through the rest of the array,
% 1 element at a time
for k=2:length(x)
% if the value at the current offset
% is smaller than our current min,
if (x(k) < min_val)
% ..then update our current min.
min_val = x(k);
end
end
% "min_val" will be returned automatically.
Finally, we can test these solutions.
>> mymin(x1)
ans =
-2
>> mymin(x2)
ans =
-2.6992
>> mymax(x1)
ans =
2
Search WWH ::




Custom Search