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 =


>> areafori(1,'i')

ans =


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
Creating Matrix Variables: Creating a matrix variable is actually just a generalization of creating a row and column vector variables. That is, the values within the row are s


An environmental consulting firm is conducting a site investigation on an abandoned industrial site that is 200 m by 150 m in size (Fig. 1). A number of piezometers were installed

Scripts to Produce and Customize the Simple Plots: The MATLAB has many graphing capabilities. In most cases, customizing plots are desired and this is the simplest to accompli

How to Open Simpower: 1. Open MATLAB 2. In the "Command Window" write ' simulink ' and press Enter or click on the Simulink icon. 3. Simulink Library Browser w

Q. An expression for a sawtooth wave over the internal 0 ≤ t ≤ T0 is given by f(t) = At/T0. The student is encouraged to check the Fourier coefficients to be a 0 = A/2, an = 0 for

#question.i want to know the number of pixels related to the actual phase value and want to separate the zero phase valued pixels from the image..

using 0de 45 how can i get the anlytical and numerical solutions for an equation,,

I have an assignment to do by MATLAB : the assignment is to design Script that makes (Panorama Stitching) for multiple pictures .. for more information see the link :