Illustrations of variable number of output arguments, MATLAB in Mathematics

Illustrations of Variable number of output arguments:

In the illustrations shown here, the user should actually know the type of the argument in order to establish how many variables to have on the left-hand side of the assignment statement. An error will answer if there are too many variables.

>> [arrtype, r,c] = typesize(4:6)

??? Error using ==> typesize

Too many output arguments.

The function nargout can be called to establish how many output arguments were used to call a function. For illustration, in the function mysize, later, a matrix is passed to the function. The functions behave like a built-in function size in that it returns the number of rows & columns. However, if three variables are used to store the answer of calling this function, then it also returns the total number of elements:

163_Illustrations of Variable number of output arguments.png

>> [r c] = mysize(eye(3))

r =

3

c =

3

>> [r c elem] = mysize(eye(3))

r =

3

c =

3

elem =

9

Note that the nargout does not return the number of output arguments in the function header, but returns the number of output arguments expected from the function (example, the number of arguments in the vector in the left-hand side of the assignment statement whenever calling the function). In a first call to the mysize function, the value of nargout be 2, therefore the function returned only the output arguments row and col. In the second call, as there were three variables on the left of the assignment statement, the value of nargout be 3, therefore the function also returned the total number of elements.

Posted Date: 10/22/2012 1:21:45 AM | Location : United States







Related Discussions:- Illustrations of variable number of output arguments, Assignment Help, Ask Question on Illustrations of variable number of output arguments, Get Answer, Expert's Help, Illustrations of variable number of output arguments Discussions

Write discussion on Illustrations of variable number of output arguments
Your posts are moderated
Related Questions
Illustration of Variance For illustration, for the vector [4, 6, 1, 5], there are n = 4 values therefore n - 1 is 3. The mean of this data set is also 4. The variance will be

Illustration of Writing to files: Here is the other illustration in which a matrix is written to a file. At First, an arbitrary 2 × 4 matrix is generated, and then it is writt

Strcat function - Concatenation : The strcat function, though, will eliminate the trailing blanks from strings before concatenating. Note that in these illustrations, the trail

Customizing Plots : There are numerous ways to customize figures in the Figure Window. On clicking the Plot Tools icon will bring up the Property Editor & Plot Browser, with ma

Blanks function: The blanks function will generate a string consisting of n blank characters-that are kind of hard to see here! Though, in a MATLAB if the mouse is moved to hi

strvcat function - concatenation: The function strvcat will concatenate it vertically, that means that it will generate a column vector of the strings.   >> strvcat(fir

Illustration of Writing variables to a file: For illustration, in the below session in the Command Window, 3 variables are generated; these are then exhibited using who. Then,

Symbolic Expression The solve function solves an equation and returns the solution(s) as symbolic expressions. The answer can be converted to numbers by using any numeric funct

Fliplr function: The fliplr function "flips" the matrix from left to right (in another words the left-most column, the first column, become the last column and so on), and the

Illustration of Logical vectors: Calling the function appears to return similar vector as simply vec > 5, and summing the result still works to determine how many elements wer