Calling a function, MATLAB Programming

Calling a Function:

Here is an illustration of the call to this function in which value returned is stored in the default variable ans:

>> calcarea(4)

ans =

50.2655

Theoretically, calling the function is completed with the name of the file in which the function resides. In order to avoid the confusion, it is simple to give the function, similar name as the filename. In this illustration, the function name is calcarea and file name is calcarea.m. The outcome returned from this function can also stored in a variable in an assignment statement; the name could be similar as the name of the output argument in the function itself but that is not essential; for illustration, either of these assignments would be fine:

>> area = calcarea(5)

area =

78.5398

>> myarea = calcarea(6)

myarea =

113.0973

The value returned from calcarea function could also be printed by using either the disp or fprintf:

>> disp(calcarea(4))

50.2655

>> fprintf('The area is %.1f\n', calcarea(4))

The area is 50.

Note that the printing is not completed in the function itself; instead, the function returns the area and then the print statement can print or exhibit it.

By using help with the function shows the adjacent block of comments under the function header:

>> help calcarea

This function computes the area of a circle.

Posted Date: 10/18/2012 7:17:37 AM | Location : United States







Related Discussions:- Calling a function, Assignment Help, Ask Question on Calling a function, Get Answer, Expert's Help, Calling a function Discussions

Write discussion on Calling a function
Your posts are moderated
Related Questions
I am doing project "Recognizing people in video based on their body" the system will use MATLAB to detect people based on thier body and then recognize them from their clothes "us


Hold and legend function: hold: is a toggle which freezes the present graph in the figure window, so that the new plots will be superimposed on the present one. Just hold

Q. Explain Power system toolbox ? Power system toolbox (PST) was developed to enable users to perform power system analysis within MATLAB. PST may be used on any computer syste

Illustration of Input function: For illustration, >> rad = input('Enter the radius: ') Enter the radius: 5 rad = 5 If character or string input is preferred, 's' s

The Efficient Method: Though, in MATLAB, there is another built-in function which specifically produces random integers, i.e. randint. Calling the function with randint (1,1,n

The following four 4 equations are needed to be plotted as CONTOUR lines on the axes space (C, T) where C is the horizontal axis, and T is the vertical axis. Contour lines for

Job: Add sinusoid with frequency 1000 Hz and amplitude 100 to the one generated in Job 1 (: Create a function using mat lab to generate a sinusoidal signal. The parameters of the s

1. Write a function to threshold your images separating the background from the foreground: Implement the "peakiness" detection algorithm described in class. The output of your