Q:

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

0

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. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now