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
Q.1: Consider the transmission of a sinusoid x(t) = cos(2f0t) through a channel a ected by multipath and Doppler. Let there be two paths, and assume the sinusoid is being sent fro

Converting between the String and Number types: The MATLAB has many functions which convert numbers to strings in which each character element is a separate digit, and vice ve

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

Example of Plotting from a Function: For illustration, the function can be called as shown below:      >> y = [1:2:9].^3      y =     1  27  125  343  729

Illustration of gauss-jordan: Here's an illustration of performing such substitutions by using MATLAB >> a = [1 3 0; 2 1 3; 4 2 3] a = 1 3 0 2 1 3 4 2

Creating Cell arrays: There are many ways to create cell arrays. For illustration, we will create a cell array in which one element will store an integer, one element store ch

Print from the structure: To print from the structure, a disp function will show either the whole structure or a field. >> disp(package) item_no: 123 cost: 19.99

Comparing strings: There are few functions which compare strings and return logical true when they are equivalent or logical false when not. The function strcmp compares the s

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

FOR Loop: The for loop, or the for statement, is used whenever it is essential to repeat statement(s) in the script or function, and whenever it is known ahead of time how man