Anonymous functions, MATLAB in Engineering

Anonymous Functions:

The anonymous function is a very easy, one-line function. The benefit of an anonymous function is that it does not have to be stored in an M-file. This can deeply simplify the programs, as often computations are very easy, and the use of anonymous functions decreases the number of M-files essential for a program. The Anonymous functions can be generated in the Command Window or in any script. The format for an anonymous function is as shown below:

fnhandle = @ (arguments) functionbody

 

here fnhandle stores the function handle; it is necessarily a way of referring to the function. The handle is assigned to this name by using the @ operator. The arguments, in the parentheses, correspond to the argument(s) which are passed to the function, merely like any other type of function. The function body is the body of the function that is any valid MATLAB expression. For illustration, here is an anonymous function which computes and returns the area of a circle:

 

>> cirarea = @ (radius) pi * radius .^2;

 

Posted Date: 10/20/2012 6:44:59 AM | Location : United States







Related Discussions:- Anonymous functions, Assignment Help, Ask Question on Anonymous functions, Get Answer, Expert's Help, Anonymous functions Discussions

Write discussion on Anonymous functions
Your posts are moderated
Related Questions
Use of While loop: Here is an illustration of calling the function, passing 5000 for the value of the input argument high. >> factgthigh(5000) ans = 5040 The itera

Finding products by for loop: an illustration, when 5 is passed to be the value of the input argument n, the function will compute and return 1 + 2 + 3 + 4 + 5, or 15: >> s

Creating a cell array: The other method of creating a cell array is easy to assign values to particular array elements and build it up element by element. Though, as explained

Patch function - graphics objects: The patch function is used to generate a patch graphics object, which is made from 2-dimensional polygons. The patch is defined by its verti

Technique to create Nested structures: This technique is the most proficient. Though, the other technique is to build the nested structure one field at a time. As this is a ne

Reading from a Mat-File: The load function is used to read from various types of files. As with save function, by default the file will be supposed to be a MAT-file, and load

Evaluating a string: The function eval is used to compute a string as a function. For illustration, below is the string 'plot(x)'is interpreted to be a call to plot the functi

Application: Menu driven Modular Program Numerous longer, more involved programs which have interaction with the user are menu-driven, that means that the program prints a men

Program of passing arguments to functions: This was an illustration of a function which did not receive any input arguments nor did it return any output arguments; it easily a