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
Expanding a function: The expand function will multiply out terms, and factor will do the opposite: >> expand((x+2)*(x-1)) ans = x^2 x-2 >> factor(ans)

Illustration of Graphics properties: A particular property can also be exhibited, for illustration, to view the line width:     >> get(hl,'LineWidth')     ans =

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 prima

Example of Menu driven modular program: As an illustration of such a menu-driven program, we will write a program to discover the constant e. The constant e, known as the n

Basic mathematical operations: All the basic mathematical operations can be executed on symbolic expressions and variables (example, add, raise to a power, multiply, subtract,

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

Vectors of Structures: In numerous applications, involving database applications, information generally would be stored in the vector of structures, instead of in individual s

Gauss, Gauss-Jordan elimination: For 2 × 2 systems of equations, there are well-defined, easy solution techniques. Though, for the larger systems of equations, finding solutio

Example to change the line width from the default: For illustration, to change the line width from the default of 0.5 to 1.5: >> set(hl,'LineWidth',1.5) As long as the

Function iscellstr - string function: The function iscellstr will return the logical true when a cell array is a cell array of all the strings, or logical false if not. >>