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
Strings: The MATLAB also handles strings that are a sequence of characters in single quotes. For illustration, using the double function on a string will represent the equival


logical operators: The logical operators are as shown below: All the logical operators operate on Boolean or logical operands. The not operator is a unary operator; wh

Water flow varies with water pressure. Two studies were made and two equations were developed: Parabolic fit:  F = 59.60180 + 3.77965 P - 0.01536 P 2       P

How do I compute and plot a temperature profile along the x axis from -6 to 6 given the equation for steady state heat conduction and boundary conditions

Random numbers: Whenever a program is being written to work with a data, and the data is not yet available, it is frequently useful to test the program first by initializing t

would you please send the programing code simultion

Obtaining the Partial Fraction Expansion of the Z-Transform expression and to find its Inverse Z-Transforms using MATLAB

An individual with $10,000 to invest has identi?ed three mutual funds as attractive opportunities. Over the last ?ve years, dividend payments (in cents per dollar invested) have be

Produce a random real number: To produce a random real number in the range from low to high, at first create the variables low and high. And then, use the expression rand*(hig