Subfunctions, MATLAB in Engineering

Subfunctions:

Though, it is possible to have more than one function in a given M-file. For illustration, if one function calls the other, the first function would be the primary function, and the function which is termed as the subfunction. Such functions both would be stored in the similar M file-first the primary function and then the subfunction. The name of the M-file would be similar as the name of the primary function, to avoid the confusion.

To elaborate this, a program which is similar to the earlier one, but computes and prints the area of a rectangle, this is as shown here. The script, or main program, first calls a function which reads the length and width of the rectangle, and then calls the function to print results. This function calls a subfunction to compute the area.

1669_Subfunctions.png

1177_Subfunctions1.png

 

Posted Date: 10/19/2012 8:19:48 AM | Location : United States







Related Discussions:- Subfunctions, Assignment Help, Ask Question on Subfunctions, Get Answer, Expert's Help, Subfunctions Discussions

Write discussion on Subfunctions
Your posts are moderated
Related Questions
Referring to and Showing Cell Array Elements and Attributes: Just as with the other vectors, we can refer to individual elements of the cell arrays. The only difference is tha

True color matrice: The true color matrices are the other way to represent images. The true color matrices are 3-dimensional matrices. The first two coordinates are the coordi

Finding products by for loop: an illustration, when 5 is passed to be the value of the input argument n, the function will compute and return 1 + 2 + 3 + 4 + 5, or 15: >> s

Interpolation and extrapolation: In most cases, it is desired to estimate values other than at the sampled data points. For illustration, we may want to estimate what the temp

Gauss-Jordan: The Gauss-Jordan elimination technique begins in similar way which the Gauss elimination technique does, but then rather than of back-substitution, the eliminati

deblank function: The deblank function eliminates only trailing blanks from the string, not leading the blanks. The strtrim function will eliminate both the leading and traili

calcrectarea subfunction: function call: area = calcrectarea(len,wid); function header: function area = calcrectarea(len, wid)   In the function call, the two arg

Square Matrices: If a matrix has similar number of rows and columns, for illustration, if m == n, the matrix is square matrix. The definitions which follow in this part apply

Use of built-in colormaps: MATLAB has built-in colormaps, it is also possible to generate others by using combinations of any colors. For illustration, the following generates

Finding sums and products: A very general application of a for loop is to compute sums and products. For illustration, rather than of just printing the integers 1 through 5, w