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
Create a GUI that has A button to bring up a dialog to select a text file and read it in. Plot the x,y values on the GUI Have text entry values, one for each parameter, in which

You are to submit your completed MATLAB code and a short written report through the Blackboard upload facility as a single zip ?le. This zip ?le should consist of your ?nite volume

khdjkafhoi woiruwoi epojrpeo

Hello! How to cipher on Matlab the message consisting eight symbols. At first the message shares on blocks. Then in each of blocks shift of symbols is carried out. The initial text

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)

Error in variables statements: Error: The expression in the left of equals sign is not a valid target for an assignment. >>  By placing a semicolon at the end of the sta

i want matlab code for DFB Equiliser and the output between tha number of iterations vs MSE

I need assistance in learning on how to do simulation of system described with an algebraic equations.

Expressions: The Expressions can be formed using values, variables which have already been formed, operators, parentheses, and built-in functions. For numbers, these can invol

MRI (magnetic resonance imaging) scanners allow doctors to now obtain complete body images for medical diagnosis purposes. The system produces scans which represent slices through