Passing Multiple Arguments:
In many situaion it is essential to pass more than one argument to the function. For illustration, the volume of a cone is given by
here r is the radius of the circular base & h is the height of cone. Hence, a function which computes the volume of a cone requires both the radius and the height:
As the function has two input arguments in function header, the two values should be passed to the function when it is called. The order makes a dissimilarity.The initial value which is passed to the function is stored in the initial input argument (in this situation, radius), and the next argument in the function call is passed to the next input argument in the function header.This is very important: The arguments in the function call should correspond one-to-one with the input arguments in the function header.
Here is an illustration of calling a function. The answer returned from the function is easily stored in the default variable ans.
>> conevol (4,6.1)
ans =
102.2065
In the next illustration, the result is printed rather with the format of two decimal places.
>> fprintf('The cone volume is %.2f\n',...
conevol(3, 5.5))
The volume of the cone is 51.84