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

1) Identify an equation that describes some chemical process.  Your equation should have at least two parameters, at least one of which should contribute in a non-linear way. He

The mass of the spring-mass-damper system shown below was initially displaced by 1 meter to the right and then released. The subsequent acceleration of the mass was measured using

Scripts to Produce and Customize the Simple Plots: The MATLAB has many graphing capabilities. In most cases, customizing plots are desired and this is the simplest to accompli

A file houseafford.dat stores on its three lines years, median incomes and median home prices for a city. The dollar amounts are in thousands. For example, it might look like this:

Printing - matrices: For matrices, the MATLAB unwinds the matrix column by column. For illustration, consider the random 2 × 3 matrix as shown below: >> mat = randint(2,3,[

Write a MATLAB program (using/making the necessary functions that you deem necessary) that does the two following jobs: It generates the following digital modulation schemes. In

Passing Multiple Arguments: In many situaion it is essential to pass more than one argument to the function. For illustration, the volume of a cone is given by here r

Function Functions: The one reason for using function handles is to be able to pass functions to the other functions-these are known as function functions. For illustration

MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions