![]() |
Functions in any programming language are some blocks of code, which could be reused whenever required, by just calling the name. It reduces so much of human effort and also rewriting of the same code, and makes the entire code big. Declaring a Function:To declare a function in MATLAB we use given below: Syntax: function [x1,x2,...,xn] = myfunc(k1,k2,...,km) Let’s understand the syntax first. Here, myfunc is the name of the function. The x1,x2,…,xn are the parameter that is sent to the function, and k1,k2,…,kn are the output obtained. Example 1: Matlab
Output: Nested Function:When you declare one function, under another parent function then it is known as a nested function. Example 2: Matlab
Output: Advantages:
Characteristics of Nested functions:You can also share variables from the nested function to the main function. Example 3: Matlab
Output: You can nest more than one function under the same parent function. Example 4: Matlab
Output: You can share variables among two nested functions, under the same parent function. Example 5: Matlab
Output: You can also handle nested functions with the help of the parent function using a variable in the parent function. Example 6: Matlab
Output: |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 9 |