Variable number of input arguments - function, MATLAB Programming

Variable number of input arguments:

For illustration, the below function areafori has a variable number of input arguments, either the 1 or 2. The name of the function stands for 'area, feet or inches.' When only one argument is passed to the function, it shows the radius in feet. When two arguments are passed, the second can be a character 'i' specifying that the result must be in inches (for any of other character, the default of feet is supposed). The function uses the built-in varargin that stores as a cell array of any number of input arguments. The nargin function returns a number of input arguments which were passed to the function. In this situation, the radius is the first argument passed; therefore it is stored in first element in the varargin. When a second argument is passed whenever nargin is 2, it is to identifyspecify the units.

1447_Variable number of input arguments.png

Note that the curly braces are used to refer the elements in the cell array varargin.

Here are some illustrations of calling this function:

>> areafori(3)

ans =

  28.2743

>> areafori(1,'i')

ans =

  452.3893

Posted Date: 10/22/2012 1:15:59 AM | Location : United States







Related Discussions:- Variable number of input arguments - function, Assignment Help, Ask Question on Variable number of input arguments - function, Get Answer, Expert's Help, Variable number of input arguments - function Discussions

Write discussion on Variable number of input arguments - function
Your posts are moderated
Related Questions
1;write the matlab of LU decomposion that can do any n*n matrix by considering scaling and pivoting?

How to make EMG analysis by Matlab?

Illustration of a conditional loop - While loop: As an illustration of a conditional loop, we will write a function which will find the first factorial which is greater than t

Calculate the gray level value for all the pixels, Computer Graphics An 8x8 image f[i,j] has gray levels given by the following equation: f [i , j]= ? i-j ? ; i,j=0,1,2,3,4,5,6,7.

Variable number of output arguments: The variable number of output arguments can also be identified. For illustration, the one input argument is passed to the below function t

Non-Ideal Gas (van der Waals equation):  An equation of state for a non-ideal which is commonly used is the van der Waals equation for 1 mol of gas  P = (R*T)/(V-b) - a/(V^2)

whats thye procedure for entering say an LP model, maximisation an objective funtion ''10x+3y'' subject to: 40 300x +298y>=299 x+y=1

what is an error and its types

Savannah says that the least common multiple of 4 and 6 is 24. Is she right or what is her mistake?

Hello my name is lalitkumar and I am a student.I needed help in MATLAB for recognition of colour randomly using webcam realtime for RGB without external trigger.please mail the co