Variable number of input arguments - function, MATLAB Programming

Assignment Help:

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


Related Discussions:- Variable number of input arguments - function

Salary calculation, write a matlab program to calculate employee salary.

write a matlab program to calculate employee salary.

CPM AND PERT, ACTIVITIES OF A PROJECT 1-2 1-3 1-4 1-5 2-6 3-6 3-7 4-7 5-7 7...

ACTIVITIES OF A PROJECT 1-2 1-3 1-4 1-5 2-6 3-6 3-7 4-7 5-7 7-6 6-8 7-8 THE COMMPANY LOSES 2,000 FOR EVERY WEEK THE PROJECT LASTS BEYOND 30 WEEKS. fOR EACH OF THE PROPOSALS; ACTIVI

College algebra, #question how to solve radicals exponents..

#question how to solve radicals exponents..

Solution by using pdepe function, Solution by using pdepe function fu...

Solution by using pdepe function functionpdex1 m = 0; x = linspace(0,1,100); t = linspace(0,0.2,10);   sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t); % Ext

Switch statement, The Switch Statement: A switch statement can frequen...

The Switch Statement: A switch statement can frequently used in place of a nested if-else or an if statement with numerous else if clauses. The Switch statements are used when

Portfolio selection problem, An individual with $10,000 to invest has ident...

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

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd