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

Size function - dimensions of matrix, Size function - Dimensions of matrix:...

Size function - Dimensions of matrix: For the matrix mat shown next, it has three rows and two columns, therefore the size is 3 × 2. The length is the larger dimension that is

Equations of motion of shaft-rotor system, Consider the shaft-rotor system ...

Consider the shaft-rotor system shown in Figure. Write down the equations of motion. Taking  I= 1 kgm 2 and k=10 kNm/rad, for two special cases (α =0.5 and α = 1000) find as many

Example of hold and legend function, Example of Hold and legend function: ...

Example of Hold and legend function: Running this script will generate two individual figure windows. If there is not any other active figure window, the first, that is the ba

To change a variable, To change a variable: To change a variable, the ...

To change a variable: To change a variable, the other assignment statement can be used that assigns the value of a different expression to it. Consider, for illustration, the

Find the value of delta equation, Solve the optimality condition for each P...

Solve the optimality condition for each P equation against M according to the following relation: Condition for Optimality:         ∇ M = λ ∇ P      with respect to C and T.

Write a matlab function, Write a MATLAB function called pgm which calculate...

Write a MATLAB function called pgm which calculates the periodogram. The function inputs should be the length input vector x and its output should be the length N periodogram estim

Linear Programming, Ft. Loudoun and Watts Bar are two large hydroelectric d...

Ft. Loudoun and Watts Bar are two large hydroelectric dams, the former upstream of the latter. The level of Watts Bar Lake must be kept within limits for recreational purposes, and

Built-in functions and help, Built-In Functions and help: There are lo...

Built-In Functions and help: There are lots of built-in functions in a MATLAB. The help command is used to find out what functions MATLAB has, and how to use them. For illustr

Error, what is an error and its types

what is an error and its types

Steady-state conduction equation, Problem: Consider a trapezoidal piece of...

Problem: Consider a trapezoidal piece of polymer film as shown below. The parallel sides of the trapezoid are insulated and the temperature of the bottom and diagonal sides are f

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