Subfunctions, MATLAB in Engineering


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.




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
Example of image processing: The other illustration generates a 5 × 5 matrix of arbitrary integers in the range from 1 to the number of colors; the resultant image is as shown

Vector operations: As vectors are special cases of matrices, the matrix operations elaborated (addition, subtraction, multiplication, scalar multiplication, transpose) work on

Illustration of if - else statement: The one application of an if-else statement is to check for errors in the inputs to a script. For illustration, a former script prompted t

Sound Files: The sound signal is an illustration of a continuous signal which is sampled to result in a discrete signal. In this situation, sound waves traveling through the a

Illustration of Sorting strings: To sort on the rows rather than second dimension should be specified. >> sort(words,2) ans = Hello Hdowy Hi Gbdeo

Function iscellstr - string function: The function iscellstr will return the logical true when a cell array is a cell array of all the strings, or logical false if not. >>

Print from the structure: To print from the structure, a disp function will show either the whole structure or a field. >> disp(package) item_no: 123 cost: 19.99

Uses of Function handles: The Function handles can also be generated for functions other than anonymous functions, both built-in & user-defined functions. For illustration, th

Illustration of anonymous functions: Dissimilar functions stored in the M-files, when no argument is passed to an anonymous function, the parentheses should still be in the fu

Splits a string : The strtok function splits a string into pieces; it can be called in many ways. The function receives one string as an input argument. It appears for the fir