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
Algorithm for the function e: The algorithm for the function eoption is as shown: Use the menu function to show the 4 choices. Error-check (an error would take place

Storing Strings in Cell Arrays: The one good application of a cell array is to store strings of various lengths. As cell arrays can store various types of values in the elemen

Creating the structure Variables: Creating a structure variable can be accomplished by simply storing the values in fields by using assignment statements, or by using the stru

Function used in sound files: The MATLAB has numerous other functions which let you read and play sound or audio files. In the audio files, sampled data for each audio channel

Changing Case: The MATLAB has two functions which convert strings to all uppercase letters, or all lowercase, known as the upper and lower. >> mystring = 'AbCDEfgh';

For Loops which do not use an iterator Variable in the action: In all the illustrations that we seen so far, the value of the loop variable has been used in same way in the ac

Binary Search: The binary search supposes that the vector has been sorted first. The algorithm is just similar to the way it works whenever looking for a name in a phone direc

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

Example of file ploting data: As the other example, a data file called 'compsales.dat' stores the sales figures (in millions) for divisions in a company. Each line in the f

Illustration of Sorting strings: To sort on the rows rather than second dimension should be specified. >> sort(words,2) ans = Hello Hdowy Hi Gbdeo