Passing multiple arguments, MATLAB Programming

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

120_Passing Multiple Arguments.png

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:

 

728_Passing Multiple Arguments1.png

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

Posted Date: 10/18/2012 7:24:11 AM | Location : United States







Related Discussions:- Passing multiple arguments, Assignment Help, Ask Question on Passing multiple arguments, Get Answer, Expert's Help, Passing multiple arguments Discussions

Write discussion on Passing multiple arguments
Your posts are moderated
Related Questions
I am trying to implement this equation u_t=-\u_x\ using upwind scheme. and as a second step, I need to put some stopping function g(h) where u_t=-g(h)\u_x\ how can I write this on

illustration of for loop: illustration, to print a column of numbers from 1 to 5: for i = 1:5 fprintf('%d\n',i) end   This loop can be entered in the Command Wi



Write a MATLAB function called pgm which calculates the periodogram. The function inputs should be the length input vector x and its output should be the length N periodogram estim

Statement of Problem I need to realise vector-array multiplication in Simulink. This has been realised in Matlab but because the process yielding the received signal is in Simu


Implement a MatLab function to calculate y.  The function should take two input arguments 1) A vector of parameters In the above example this would be of length 3, the first

Write a script to determine the volume of a pyramid, which is 1/3 * base * height, where the base is length * width. On time the user to enter values for the length, width, and th

Obtain the input - Algorithms: From where does the input come? The two possible choices would be from an external file on a disk, or from the user, who enters the number by ty