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
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

I have a vector of X, one for Y , one for x-direction velocity U and one for y-direction velocity V. they are at same size. How can I plot streamline of that flow? I follow all exa

function imread: The function imread can read an image file, for illustration a JPEG (.jpg) file. The function reads color images into a 3-dimensional matrix. >> myimage1

Built-in colormaps: The MATLAB has numerous built-in colormaps which are named; the reference page on colormap shows them. Calling the function colormap without passing any ar

Implementation of binary search: The binary search can be implemented as a recursive function. The recursive function below also implements this binary search algorithm. It re

function numden: The function numden will return individually the numerator & denominator of a symbolic expression: >> sym(1/3 + 1/2) ans = 5/6 >> [n, d] =

Function used in binary search: The function below implements this binary search algorithm. It receives two arguments: the sorted vector and a key (on the other hand, the func

Sound Files: The sound signal is an illustration of a continuous signal which is sampled to result in a discrete signal. In this situation, sound waves traveling through the a

Square Matrices: If a matrix has similar number of rows and columns, for illustration, if m == n, the matrix is square matrix. The definitions which follow in this part apply

Algorithm for appex subfunction: The algorithm for appex subfunction is as shown:  Receives x & n as the input arguments.  Initializes a variable for running sum of t