Numeric, cell arrays, matrix operations, user defined functions, programming using MATLAB; debugging MATLAB programs, applications to simulations
COM 103 ICT Applications in Food Industry (1+2)
Lecture Schedule 5 – Part - III
Dr. S. Sridevy, Ph.D.
Assistant Professor (Computer Science)
Dept. of Physical Sciences & IT
AEC&RI, TNAU, Coimbatore – 3.
22 June 2020
Variable Editor Window
S. Sridevy
22 June 2020
S. Sridevy
22 June 2020
User Defined Functions
S. Sridevy
22 June 2020
User Defined Functions (Contd.)
S. Sridevy
22 June 2020
User Defined Functions (Contd.)
S. Sridevy
22 June 2020
User Defined Functions (Contd.)
function [y1,...,yN] = myfun(x1,...,xM)
S. Sridevy
22 June 2020
User Defined Functions (Contd.)
S. Sridevy
22 June 2020
User Defined Functions (Contd.)
S. Sridevy
22 June 2020
User Defined Functions (Contd.)
S. Sridevy
22 June 2020
Syntax Elaborated
S. Sridevy
22 June 2020
Function Keyword
S. Sridevy
22 June 2020
Output arguments (optional)
function myOutput = myFunction(x)
function [one,two,three] = myFunction(x)
S. Sridevy
22 June 2020
Output arguments (optional)
function myFunction(x)
function [] = myFunction(x)
S. Sridevy
22 June 2020
Function name
S. Sridevy
22 June 2020
Input arguments
function y = myFunction(one,two,three)
S. Sridevy
22 June 2020
Example 1
function f = fact(n)
f = prod(1:n);
end
S. Sridevy
22 June 2020
Example 1 (Contd.)
x = 5;
y = fact(5)
y =
120
S. Sridevy
22 June 2020
Example 1 (Contd.)
S. Sridevy
22 June 2020
Example 2
S. Sridevy
22 June 2020
Example 2 (Contd.)
x = 3;
y = 2;
z = perm(x,y)
function p = perm(n,r)
p = fact(n)*fact(n-r);
end
function f = fact(n)
f = prod(1:n);
end
S. Sridevy
22 June 2020
Example 2 (Contd.)
mystats
z =
6
S. Sridevy
22 June 2020
Thank You!