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
Random numbers: Whenever a program is being written to work with a data, and the data is not yet available, it is frequently useful to test the program first by initializing t

Solution by using pdepe function functionpdex1 m = 0; x = linspace(0,1,100); t = linspace(0,0.2,10);   sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t); % Ext

Various commands for get the help: There are various commands which can serve as an introduction to MATLAB and allow you to get the help: info will show contact informatio

I want to write a function in matlab which gives me a population pyramid bar chart. could you please help me do this.


the basic equation of modeling radioactive decay is where the amount of the radioactive substance is at time and is the decay rate. Some radioactive substances decay into other rad

Introduction to File Input/output (LOAD and SAVE): In most cases, the input to a script will come from a data file which has been generated by the other source. It is also use

Algorithms: Before writing any computer program, it is very useful to first outline the steps which will be essential. An algorithm is the series of steps required to solve a

Mathematical operation: For numerical operands, the use of such operators is clear-cut. For illustration, 3 >> 3 ans = 1 >> 9 ans = 0 Though, in the Wo

Looping Statements: Consider the problem of computing the area of a circle with radius of 0.3 centimeters-a MATLAB program certainly is not required to do that; you would use