![]() |
Function Handles are a data type of MATLAB which represents a function. They store a function just like an ordinary variable store numeral or alphabetic data. An example of the same could be a function, say f1, that takes another function, f2, as its parameter; f2 calculates a mathematical function over some range. This is just one of the many ways, one could use function handles in MATLAB. Let us see how these function handles are created and used in MATLAB. Creating Function Handles:Function handles can be created using the @ operator. The syntax is as follows:
Now, see the following examples for Function Handles. Let us first create a simple handle that calls a function fun which calculates the cube of a given number. Example 1: Matlab
Output: This creates a function handle fh for the fun function. This would give the result as follows: ![]()
Now let us do some better use of the function handle by passing it to another function. Example 2: Matlab
Output: This would calculate the integral of the cube of x over the range 0 to 3. ![]()
|
Reffered: https://www.geeksforgeeks.org
MATLAB |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |