Write a function mymin that will receive any number of arguments, and will return the minimum. Note: the function is not receiving a vector; rather, all of the values are separate arguments
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:14| Question number:2.14
All Answers
total answers (1)
mymin.m
function small = mymin(varargin)
% Receives any # of arguments, and returns the minimum
% Format of call: mymin(arguments)
% Returns the minimum of the arguments
n = nargin;
%Set initial value for the min
small = varargin{1};
%Loop through the remaining inputs and reassigning the min if a
smaller
%value is found
for i = 2:n
if small > varargin{i}
small = varargin{i};
end
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer