SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Function Function
Local Function
Private Function
MOREON
USERDEFINEDFUNCTION
Shameer A Koya
http://electricalenggtutorial.blogspot.com
A function handle is a data type that stores an
association to a function.
the functions can be built-in, user defined, or
anonymous
It is used to call a function indirectly.
To make a function handle for built-in or user-
defined function, put the @ symbol in front of
function name
fhandle = @functionname
function handle for MATLAB ones function is @ones
FUNCTION HANDLE
Typical uses are:
Pass a function to another function
(called function functions).
Specify callback functions. (GUI
programming)
Construct handles to inline functions or
anonymous functions.
Call local functions from outside the main
function
USES OF FUNCTION HANDLE
 Anonymous function
sqr = @(x) x.^2
 Calling function indirect:
function y = Sqr(x)
y = x.^2;
end
f = @Sqr;
a = 2;
b = f(a);
b =
4
 Pass to another function
z = integral(f,0,1);
EXAMPLES
A MATLAB function that accepts another
function as an input is called a function
function
Function handles are used for passing
functions to function functions
Syntax for function function is same as simple
functions, but one or more input arguments
will be function handles.
FUNCTION FUNCTIONS
 From the previous example:
z = quad(f,0,1);
z =
0.33333
 Calculate the integral for the interval specified.
fzero(@sqr,-3,3)
 Finds the zeros of the function with in the range
 Can be used to plot the functions
x = linspace(-3,3,100);
figure;
plot(x,f(x))
EXAMPLES
 Multiple functions within one function file
 Name of function file should be name of main
function.
 Main function can be called from the command
window or any other function.
 Local functions are typed in any order after the
main function.
 Local functions are only visible to other functions in
the same file. (They are not visible to the functions
out side or command window).
LOCAL FUNCTION (SUB-FUNCTION)
function [a, b, c] = basicmath(x, y)
% basicmath is the main function.
a = add(x,y);
b = sub(x,y);
c = mult(x,y);
end
function l = add(u,v)
% add is a local function.
l = u+v;
end
function m = sub(u,v)
% sub is another local function.
m = u-v;
end
function n = mult(u,v)
% sub is another local function.
n = u*v;
end
EXAMPLE
 A private function is a function residing in a
subdirectory with the name private.
 Private functions are visible only to functions in the
parent directory.
 They are useful when we want to limit the scope of
a function.
 You cannot call the private function from the
command line or from functions outside the parent
of the private folder.
PRIVATE FUNCTIONS

Weitere ähnliche Inhalte

Was ist angesagt?

Prsentation on functions
Prsentation on functionsPrsentation on functions
Prsentation on functions
Alisha Korpal
 

Was ist angesagt? (20)

Prsentation on functions
Prsentation on functionsPrsentation on functions
Prsentation on functions
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
M11 operator overloading and type conversion
M11 operator overloading and type conversionM11 operator overloading and type conversion
M11 operator overloading and type conversion
 
C function presentation
C function presentationC function presentation
C function presentation
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
Built in function
Built in functionBuilt in function
Built in function
 
user defined function
user defined functionuser defined function
user defined function
 
Function
FunctionFunction
Function
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)
 
Function in c
Function in cFunction in c
Function in c
 
Function in C program
Function in C programFunction in C program
Function in C program
 
C++ lecture 03
C++   lecture 03C++   lecture 03
C++ lecture 03
 
functions of C++
functions of C++functions of C++
functions of C++
 
Method parameters in c#
Method parameters in c#Method parameters in c#
Method parameters in c#
 
predefined and user defined functions
predefined and user defined functionspredefined and user defined functions
predefined and user defined functions
 

Andere mochten auch

Loops in matlab
Loops in matlabLoops in matlab
Loops in matlab
TUOS-Sam
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
TUOS-Sam
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlab
TUOS-Sam
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
Suneel Dogra
 

Andere mochten auch (20)

MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2
 
Conditional Control in MATLAB Scripts
Conditional Control in MATLAB ScriptsConditional Control in MATLAB Scripts
Conditional Control in MATLAB Scripts
 
Matlab time series example
Matlab time series exampleMatlab time series example
Matlab time series example
 
Introduction to Matlab Scripts
Introduction to Matlab ScriptsIntroduction to Matlab Scripts
Introduction to Matlab Scripts
 
Loops in matlab
Loops in matlabLoops in matlab
Loops in matlab
 
Matlab Script - Loop Control
Matlab Script - Loop ControlMatlab Script - Loop Control
Matlab Script - Loop Control
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
 
MATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output CommandsMATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output Commands
 
R Programming: Numeric Functions In R
R Programming: Numeric Functions In RR Programming: Numeric Functions In R
R Programming: Numeric Functions In R
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlab
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
metode numerik stepest descent dengan rerata aritmatika
metode numerik stepest descent dengan rerata aritmatikametode numerik stepest descent dengan rerata aritmatika
metode numerik stepest descent dengan rerata aritmatika
 
Modul1 metode bagi dua Praktikum Metode Numerik
Modul1 metode bagi dua Praktikum Metode NumerikModul1 metode bagi dua Praktikum Metode Numerik
Modul1 metode bagi dua Praktikum Metode Numerik
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
 
Modul2 metode regula falsi praktikum metode numerik
Modul2 metode regula falsi praktikum metode numerikModul2 metode regula falsi praktikum metode numerik
Modul2 metode regula falsi praktikum metode numerik
 
Fungsi grafik di matlab
Fungsi grafik di matlabFungsi grafik di matlab
Fungsi grafik di matlab
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
Metode numerik-buku-ajar-unila
Metode numerik-buku-ajar-unilaMetode numerik-buku-ajar-unila
Metode numerik-buku-ajar-unila
 
MATLAB Scripts - Examples
MATLAB Scripts - ExamplesMATLAB Scripts - Examples
MATLAB Scripts - Examples
 

Ähnlich wie User Defined Functions in MATLAB Part-4

D-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptxD-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptx
VedantSahane
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
Jeevan Raj
 

Ähnlich wie User Defined Functions in MATLAB Part-4 (20)

User defined functions in matlab
User defined functions in  matlabUser defined functions in  matlab
User defined functions in matlab
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
 
D-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptxD-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptx
 
C functions list
C functions listC functions list
C functions list
 
Functions
Functions Functions
Functions
 
function of C.pptx
function of C.pptxfunction of C.pptx
function of C.pptx
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
 
Funtion
FuntionFuntion
Funtion
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
 
eee2-day4-structures engineering college
eee2-day4-structures engineering collegeeee2-day4-structures engineering college
eee2-day4-structures engineering college
 
Function
FunctionFunction
Function
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Functions
FunctionsFunctions
Functions
 
Funkcija, objekt, python
Funkcija, objekt, pythonFunkcija, objekt, python
Funkcija, objekt, python
 

Kürzlich hochgeladen

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Kürzlich hochgeladen (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 

User Defined Functions in MATLAB Part-4

  • 1. Function Function Local Function Private Function MOREON USERDEFINEDFUNCTION Shameer A Koya http://electricalenggtutorial.blogspot.com
  • 2. A function handle is a data type that stores an association to a function. the functions can be built-in, user defined, or anonymous It is used to call a function indirectly. To make a function handle for built-in or user- defined function, put the @ symbol in front of function name fhandle = @functionname function handle for MATLAB ones function is @ones FUNCTION HANDLE
  • 3. Typical uses are: Pass a function to another function (called function functions). Specify callback functions. (GUI programming) Construct handles to inline functions or anonymous functions. Call local functions from outside the main function USES OF FUNCTION HANDLE
  • 4.  Anonymous function sqr = @(x) x.^2  Calling function indirect: function y = Sqr(x) y = x.^2; end f = @Sqr; a = 2; b = f(a); b = 4  Pass to another function z = integral(f,0,1); EXAMPLES
  • 5. A MATLAB function that accepts another function as an input is called a function function Function handles are used for passing functions to function functions Syntax for function function is same as simple functions, but one or more input arguments will be function handles. FUNCTION FUNCTIONS
  • 6.  From the previous example: z = quad(f,0,1); z = 0.33333  Calculate the integral for the interval specified. fzero(@sqr,-3,3)  Finds the zeros of the function with in the range  Can be used to plot the functions x = linspace(-3,3,100); figure; plot(x,f(x)) EXAMPLES
  • 7.  Multiple functions within one function file  Name of function file should be name of main function.  Main function can be called from the command window or any other function.  Local functions are typed in any order after the main function.  Local functions are only visible to other functions in the same file. (They are not visible to the functions out side or command window). LOCAL FUNCTION (SUB-FUNCTION)
  • 8. function [a, b, c] = basicmath(x, y) % basicmath is the main function. a = add(x,y); b = sub(x,y); c = mult(x,y); end function l = add(u,v) % add is a local function. l = u+v; end function m = sub(u,v) % sub is another local function. m = u-v; end function n = mult(u,v) % sub is another local function. n = u*v; end EXAMPLE
  • 9.  A private function is a function residing in a subdirectory with the name private.  Private functions are visible only to functions in the parent directory.  They are useful when we want to limit the scope of a function.  You cannot call the private function from the command line or from functions outside the parent of the private folder. PRIVATE FUNCTIONS