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
Program to Counting in a while loop: The script initializes variable counter to 0. Then, in the while loop action, each and every time the user successfully enter a number, th

Algorithm for subfunction: The algorithm for subfunction askforn is as shown:  Prompt the user for the positive integer n.  Loop to print an error message and reprom

. Generate the following signal, x(n)=1+cos((25*pi*n)/100),0 Compute the DTFT of x[n] for w=0:0.01:2*pi Plot the Real part, imaginary part, the amplitude and phas

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

Passing arguments to functions: In all these functions examples faraway, at least one of the arguments was passed in the function call to be the value(s) of the equivalent inp

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

str2num function - String: The function str2num does the opposite; it takes the string in which a number is stored and converts it to the type double: >> num = str2num('123.

Variable Scope: The scope of any of variable is the workspace in which it is valid. The workspace generated in the Command Window is known as the base workspace. As we know

Illustration sorting vectors of structures: This function sorts the structures depend only on the price field. A more common function is shown next, that receives a string whi