SlideShare a Scribd company logo
1 of 48
Rounding functions
• Different function to round numbers: A = [-1.9, -0.2, 3.4, 5.6, 7.0, 2.4+3.6i]
– fix(A) = [-1 0 3 5 7 2+3i]
– ceil(A) = [-1 0 4 6 7 3+4i]
-floor(A) = [-2 -1 3 5 7 2+3i]
– round(A) = [-2, 0 3 6 7 2+4i]
mod(X,Y) rem(X,Y)
• Returns the remainder of X and
Y
• mod (x,0) =x
• mod retains the sign of Y
x mod y
11 mod 5 = 1
-11 mod 5 = 4
11 mod -5 = -4
-11 mod -5 = -1
• Returns the remainder of X and
Y
• rem(x,0)=NaN
• rem retains the sign of X
x rem y
11 rem 5 = 1
-11 rem 5 = -1
11 rem -5 = 1
-11 rem -5 = -1
George Iskander - ITI 2
Mathematical operation
Matrix Indexing
• B = A(1,1)  B = 1
• C = A(2,3)  C =2
• D = A(6)  D =9
• E = A(1, [1,2,3] )  A( 1st Row, Columns: 1,2 and 3) = 1 3 7
• F = A(1, : )  similar to A(1,1:3) = 1 3 7
• G = A(3 , 4) A(3rd Row, 4th Column)  Index exceeded matrix dimensions)
• H = A( [1,3] , : )  A(Rows: 1 & 3 , All Columns) = [1 3 7; 8 90]
• I = A(: , : )  A(All Rows, All Columns) = [1 3 7; -5 4 2; 8 90]
• J = A(end,2)  A(Last Row,2) = 9 3
Matrix Indexing
• B = A( : )  A(Allelements)
B =
1
-5
8
3
4
9
7
2
0
• D = A([2 3 1],[1 3 2 1])
D =
-5 2 4 -5
8 0 9 8
1 7 3 1
4
Matrix Indexing (Assigning Value)
• A (1,1) = 5
• A(6) = 20
• A(1, [1,2,3] ) = [1 2 3]
• A(3 , 4) = 7new column will be added
• A( [1,3] , : ) = [4 7 4 1; 3 2 5 1]
• A( [2,4] , [2,3] ) = -2.5*ones(2,2) new row will be added
• A(end) = 78 ; A( 2, 1:end ) = [ 4 4 4 4]
• A(end+1,end-1)=6 ; A(1:end,2:3)=[20 30;40 50;60 70;80 90;100 110]
5
Eigen Values and Eigen Vectors
Definition: A scalar λ is called an eigenvalue of the
matrix A(n*n) where it is a nontrivial solution of A𝑥 = λ 𝑥.
Such 𝑥 is called an eigenvector corresponding to the
eigenvalue λ.
A 𝑥 = λ 𝑥
A 𝑥 − λ 𝑥 = 0
A 𝑥 − λI 𝑥 = 0
(A − λI) 𝑥 = 0
 det( A − λI) =0
Characteristic Equation of a system
 Checkeig(A)
6
For a multidimensional array
• Enter a 3D matrix:
– >> x = [1 2 3; 4 5 6; 7 8 9];
– >> x(:,:,2) = x’;
• Check sum(x,1), prod(x,2) and mean (x,3)
>> y = sum(x,1) >> y = prod(x,2) >> y = mean(x,3)
y(:,:,1) =
12 15 18
y(:,:,2) =
6 15 24
y(:,:,1) =
6
120
504
y(:,:,2) =
28
80
162
y=
1 3 5
3 5 7
5 7 9
size(y) = 1 3 2 size(y) = 3 1 2 GesoirzgeeI(syka)nd=er3-I3TI 7
A < B
A <= B
A > B
A >= B
A == B
A ~= B
• Returns a logical array
8
• Logical Values:
– Any nonzero value MATLAB consider as TRUE
– Zero value MATLAB consider as FALSE
– MATLAB always returns 1 as TRUE and 0 as FALSE
• Short Circuit
• && and || accept scalar values only.  For Conditions
• For arrays (element-wise) & (and(A,B)) and | (or(A,B))
 check >> 1.4 < sqrt(2) & [pi > 3 -1 > 1]  Scalar with vector
• xor(A,B) , not(A)
9
• MATLAB Fundamentals
• Programming with MATLAB
• MATLAB Toolboxes “Control Toolbox – Symbolic Toolbox”
• Simulink
• Data Type, Plotting and Fitting, Logical Index
• Introduction to GUI
• Extra :
 Connecting Hardware with Matlab
 Linking Matlab, Labview and Solidworks 10
• Input and Output Commands
 Text Interface
 GUI Interface
• Programming with MATLAB
 M-file script and MATLAB function
• Control Flow
 If condition
 Switch condition
 For loop
 While loop
• Polymorphismic Function
• Comment and Sections
11
Text Interface
• input()  Request user input
>> prompt = ‘Enter the description of the required input’
>> result = input(prompt)  the input is stored as it is entered
>> str = input(prompt,'s')  the input is stored as a string
• If you press the Return key without entering anything, then input returns an empty
matrix.
12
Text Interface
• disp() – display() :
 disp(X) displays the X array, without printing thearray name. It 's the same as you
write a statement without semicolon except that empty arrays don't display.
 display(X) it differs from disp() that it displays the name of thevariable
• MATLAB invokes the built-in display() when MATLAB executes a statement that
returns a value and is not terminated with a semicolon.
• MATLAB invokes the built-in disp function when the built-in display function calls
disp.
13
Text Interface
• fprintf()
 It is mainly used to write data to a file but we can use it to write to the screen directly. With
addition property to control the format specification.
 fprintf(FORMAT,A1,...,An) formats data and displays the results on the screen.
FORMAT is a string that describes the format of the output fields, and can include
combinations of the following:
* Literal text to print.
* Escape characters, including: b Backspace ‘ ‘ Single quotation mark
f Form feed %% Percent character
n New line  Backslash
r Carriage return t Horizontal tab
14
Text Interface
• fprintf()
*Conversion specifications, which include a % character, a conversion character (such
as d, i, o, u, x, f, e, g, c, or s), and optional flags, width, and precision fields.
• Towrite on a file  fopen(), fclose() are used
– fprintf(fileid, format, A1,…,An)
15
Text Interface
• error()
Similar to fprintf; where a message in red appear on the command window as the
default error message that is done by MATLAB and the code is terminated
>> error('nX must be at least %4.2f mmn',5.634)
X must be at least 5.63 mm
 Check the difference with warning()
16
GUI Interface
• inputdlg()
prompt = {'Enter your name:', 'Enter your age:'};
titlename =‘Personal Information';
numlines=1;
default={‘Mahmoud Hussein',‘25'};
ANSWER = inputdlg(prompt, titlename, numlines, default)
Example 2:
x = inputdlg({'Name','Telephone',’Address’,'Account'}, …
'Customer Information ', [1 50; 1 12;2 50; 1 7])
Output is stored
in cell array
17
GUI Interface
• menu()
choice = menu('mtitle','opt1','opt2',...,'optn')
choice = menu('mtitle',{'opt1','opt2',...,'optn‘})
Example:
choice = menu('What is your department?', 'Java ', 'Mechatronics', 'GIS')
Output is integer
refering to the order
of your choice
18
GUI Interface
• questdlg()
button = questdlg('qstring','title')  By default (the choices are Yes, No and Cancel)
button = questdlg(‘Is the course useful? ',‘Feedback',‘Yes',‘No', ‘May be‘, ‘Yes’)
Output is a
string similar to
your choice
19
GUI Interface
Example:
 Check listdlg
How to do
it?
20
GUI Interface
•msgbox()
msgbox(message, title, icon)
message=‘Help me’
title = Help
icon= 'help‘ % It can be 'none', 'error', 'warn' or 'help'. The default is 'none'
• errordlg()
errordlg(message, title)
• waitbar(x)  x varies from 0 to 1
 Check warndlg(), helpdlg()
21
George Iskander - ITI 22
• Any command written
directly on the
command window
• Directly processed
and the output will
directly appear on the
command window
• Any command written
directly on the
command window
• Directly processed
and the output will
directly appear on the
command window 23
M-file Script
• A group of statements that are processed in sequence altogether.
• These statements do a certain function.
• No argument can be passed to the M-file before running
• Has direct effect on the workspace
• Before running the script, it must be save in an m-file *.m
Conditions for choosing m-file name: Calling the script
• Refers to the function of the script
• Same as variables
• Be sure no overlap with other
built-in function. Check exist()
• Press Run on the editor toolbar
• Write the name of the m-file
directly on the command window
• Can be called inside other script
24
M-file Script
• Example 1:
• Write an M-file that:
– Plot a given function from user
– Plot it’s derivative
– Plot it’s integration
– Identify the peaks and valleys of the main function
• Used functions : cumtrapz() – plot() – text() – gtext() – title()
25
George Iskander - ITI 26
M-file Script
• Example 2:
• Write an M-file that:
– Plot a given function from user
– Perform a limit integration according to the user input
• Used functions : trapz() – area() – ginput()
27
MATLAB Function
• A group of statements that are processed in sequence altogether.
• The first sentence must declare that the script is a function. Specify the inputs,
outputs and the name of the function.
• Argument can be passed to the function while calling it as well as assigning variables
for outputs based on the prototype
• Has its own workspace, (different scope)
• Before running the function, it must be save
in an m-file *.m with the same name of the
function (same rules)
Calling the Function
• Press Run on the editor toolbar ,if
no required arguments
•Write the name of the function
directly on the command window
• Can be called inside other script
28
MATLAB Function
•Example 1:
function myRand
a= 5+rand(3,4)*2
end
1- We need a variable to hold the output of the function
• Example 2:
function a = myRand
a= 5+rand(3,4)*2;
end
Activity 1: Check the value of
• max(round(a))
• min(round(a))
• max(fix(a))
• min(fix(a))
You can find the
variable ‘a’ in the
workspace
29
MATLAB Function
2- We need to declare variables to pass input to the function
• Example 3:
function a = myRand (low,high)
a= low+rand(3,4)*(high-low);
end
3- General form (accept no. of rows and coloums and the range)
• Example 4:
function a = myRand(row,col,low,high)
a= low+rand(row,col)*(high-low);
end
The order of the input
is very important
30
MATLAB Function
4- We can have more than one output
• Example 5a:
function a = myRand(row,col,low,high)
a = low+rand(row,col)*(high-low);
a(end+1,end+1) = sum(a(:));
end
Example 5b:
function [a, sumno] = myRand(row,col,low,high)
a = low+rand(row,col)*(high-low);
sumno = sum(a(:));
end
Compare
both
functions
31
MATLAB Function
5- We can have more than one function
• Example 6:
function [a, sumno] = myRand(row,col,low,high)
a = low+rand(row,col)*(high-low);
sumno = sumelements(a(:));
end
function x = sumelements(mat)
x = sum(mat(:));
end
Run it step by
step and check
the change in
workspace
32
Debugging Tools
33
Debugging Tools
34
Build the following function
1. Write a function called odd_index that takes a matrix, M, as input argument and
returns a matrix that contains only those elements of M that are in odd rows and
columns. Note that both the row and the column of an element must be odd to be
included in the output.
2. Write a function called int_col that has one input argument, a positive integer n
that is greater than 1, and one output argument v that is a column vector of length
n containing all the positive integers from 1 to n, arranged in such a way that no
element is equal to its own index value.
3. Write a function called pitty that takes a matrix called ab as an input argument. The
matrix ab has exactly two columns. The function should return a column vector c
that contains (a^2 + b^2)^0.5 = c,
35
• if loop
• switch case
• for loop
• while loop
• try and catch
36
if Loop
• If the condition is true , a group of commands are executed,
otherwise we jump to complete the rest of the program
if (condition)
--------
--------
end
Commands
Yes
37
No
if - else Loop
• If the condition is true , a group of commands are executed,
otherwise another group of commands are executed then
the rest of the program is completed normally
if (condition)
--------
--------
else
--------
--------
end
Commands
38
Yes
No
Commands
Nested if Loop
• If- elseif – else statement
if (condition)
--------
--------
elseif (condition)
--------
--------
else
--------
--------
end
Commands
Yes
No
Commands Commands
Yes
No
Until the first
39
conditionis
true
switch case
• Check the value of a variable, if it is equal to a certain
value (case), the commands below it will be executed.
• If no case is correct, a default block may be added at the
end with a key word called otherwise
switch x
case 1
--------
case 2
--------
case 3
--------
otherwise
--------
end
Commands
Commands
Commands
Commands
Yes
No
Yes
No
Yes
No
In case you
want more
than one value
in a case use { }
40
for Loop
• When you need to repeat a certain steps for a known
number of times
for i = 1:n
--------
--------
end
This loop will be repeated length of i times
• A very strong feature that it can have variable step also it
can be a cell array with different data types
i= {‘hi’, *1:5], 3, [1:3;4:6]}
Intialize
Commands
update
Yes
No
41
while Loop
• We you need to repeat a certain steps as long as a certain
condition is true
while (condition)
--------
--------
end
Commands
Yes
No
42
break – continue - return
43
• break : Terminate execution of WHILE or FOR loop.
– It will end the specified loop, will not complete the rest of iteration. If nested
loops, will terminate the innermost loop only
• continue : Pass control to the next iteration of FOR or WHILE loop without
completing the current iteration, skipping any remaining statements in the body
• return : when executed it returns to the invoking function
– Normally functions return when the end of the function is reached. But a return
statement can be used to force an early return.
try and catch
Type 1: Type 2: Explaination
try
--------
--------
end
If error occurred the
rest of the loop will
not be completed
without an error
message
try
--------
--------
catch ME
--------
--------
end
• The statements
between the try and
catch are executed.
However, if an error
occurs while execution,
the error is captured
into an object, ME
(optional) and the
statements between
the CATCH and END
are executed.
44
Try and catch
>> A=input(‘Matrix=’);
>>try
>>B=inv(A);
>>catch
>>msgbox(‘matrix is not aquare’)
>>end
General Form
• How to make our myrand function a polymorphism?
• nargin  a variable that holds the number of input argument
• nargout  a variable that holds the number of output argument
• Implement it on myRand function to be generic function
46
Variable I/P and Variable O/P
• How to make a function that can have variable number of input or output?
• function [s, varargout] = myfun(x, varargin)
– varargin : Allows any number of arguments to a function. The variable
varargin is a cell array containing the optional arguments to the function. It must be
declared as the last input argument and collects all the inputs from that point
onwards.
– varargout : Allows any number of arguments out of a function. The variable
varargin is a cell array containing the optional arguments of the function. It must
be declared as the last output argument and must contains all the outputs after
that point onwards
47
% Toadd a comment. Anything after it will be ignored
% If you write it under a declared function immediate , it will be the help of your
function when you the user will ask for help
%% In M-file, to run a separate part.
48

More Related Content

What's hot

INTRODUCTION TO MATLAB session with notes
  INTRODUCTION TO MATLAB   session with  notes  INTRODUCTION TO MATLAB   session with  notes
INTRODUCTION TO MATLAB session with notesInfinity Tech Solutions
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programmingAhmed Moawad
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Randa Elanwar
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab FunctionsUmer Azeem
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arraysAmeen San
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical ComputingNaveed Rehman
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programmingDamian T. Gordon
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problemsMake Mannan
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)harman kaur
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlabkrajeshk1980
 
MATLAB - The Need to Know Basics
MATLAB - The Need to Know BasicsMATLAB - The Need to Know Basics
MATLAB - The Need to Know BasicsSTEM Course Prep
 

What's hot (20)

INTRODUCTION TO MATLAB session with notes
  INTRODUCTION TO MATLAB   session with  notes  INTRODUCTION TO MATLAB   session with  notes
INTRODUCTION TO MATLAB session with notes
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab Functions
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
 
matlab
matlabmatlab
matlab
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
 
Intro to matlab
Intro to matlabIntro to matlab
Intro to matlab
 
Matlab1
Matlab1Matlab1
Matlab1
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
Matlab commands
Matlab commandsMatlab commands
Matlab commands
 
MATLAB - The Need to Know Basics
MATLAB - The Need to Know BasicsMATLAB - The Need to Know Basics
MATLAB - The Need to Know Basics
 

Similar to Mbd2

Similar to Mbd2 (20)

An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
 
Basic concept of MATLAB.ppt
Basic concept of MATLAB.pptBasic concept of MATLAB.ppt
Basic concept of MATLAB.ppt
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Image processing
Image processingImage processing
Image processing
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
Programming in R
Programming in RProgramming in R
Programming in R
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Mat lab
Mat labMat lab
Mat lab
 
Lecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdfLecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdf
 
Getting started cpp full
Getting started cpp   fullGetting started cpp   full
Getting started cpp full
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
introduction to matlab.pptx
introduction to matlab.pptxintroduction to matlab.pptx
introduction to matlab.pptx
 
Python High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptPython High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.ppt
 
Matlab ch1 (6)
Matlab ch1 (6)Matlab ch1 (6)
Matlab ch1 (6)
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
 

More from Mahmoud Hussein

More from Mahmoud Hussein (20)

07 modelling.electric.motors
07 modelling.electric.motors07 modelling.electric.motors
07 modelling.electric.motors
 
Dc dc converter
Dc dc converterDc dc converter
Dc dc converter
 
08 pid.controller
08 pid.controller08 pid.controller
08 pid.controller
 
06 control.systems
06 control.systems06 control.systems
06 control.systems
 
05 tuning.pid.controllers
05 tuning.pid.controllers05 tuning.pid.controllers
05 tuning.pid.controllers
 
02 physical.system.modelling mechanical.systems.
02 physical.system.modelling mechanical.systems.02 physical.system.modelling mechanical.systems.
02 physical.system.modelling mechanical.systems.
 
03 dynamic.system.
03 dynamic.system.03 dynamic.system.
03 dynamic.system.
 
Lecture 02 laplace transformation
Lecture 02 laplace transformationLecture 02 laplace transformation
Lecture 02 laplace transformation
 
Model based design-Hardware in loop-software in loop
Model based design-Hardware in loop-software in loopModel based design-Hardware in loop-software in loop
Model based design-Hardware in loop-software in loop
 
Ac drive basics
Ac drive basicsAc drive basics
Ac drive basics
 
Velocity kinematics
Velocity kinematicsVelocity kinematics
Velocity kinematics
 
MPI Communication
MPI CommunicationMPI Communication
MPI Communication
 
ERROR
ERRORERROR
ERROR
 
Analogue Module
Analogue ModuleAnalogue Module
Analogue Module
 
Function Block & Organization Block
Function Block & Organization BlockFunction Block & Organization Block
Function Block & Organization Block
 
Data Block
Data BlockData Block
Data Block
 
Declaration Table
Declaration TableDeclaration Table
Declaration Table
 
Math operation
Math operationMath operation
Math operation
 
Industrial communication
Industrial communicationIndustrial communication
Industrial communication
 
Computer vision
Computer visionComputer vision
Computer vision
 

Recently uploaded

Beautiful Vip Call Girls Punjabi Bagh 9711199012 Call /Whatsapps
Beautiful Vip  Call Girls Punjabi Bagh 9711199012 Call /WhatsappsBeautiful Vip  Call Girls Punjabi Bagh 9711199012 Call /Whatsapps
Beautiful Vip Call Girls Punjabi Bagh 9711199012 Call /Whatsappssapnasaifi408
 
VIP Kolkata Call Girl Kasba 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kasba 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kasba 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kasba 👉 8250192130 Available With Roomdivyansh0kumar0
 
Call Girl Service Global Village Dubai +971509430017 Independent Call Girls G...
Call Girl Service Global Village Dubai +971509430017 Independent Call Girls G...Call Girl Service Global Village Dubai +971509430017 Independent Call Girls G...
Call Girl Service Global Village Dubai +971509430017 Independent Call Girls G...kexey39068
 
Digamma - CertiCon Team Skills and Qualifications
Digamma - CertiCon Team Skills and QualificationsDigamma - CertiCon Team Skills and Qualifications
Digamma - CertiCon Team Skills and QualificationsMihajloManjak
 
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGER
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGERUNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGER
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGERDineshKumar4165
 
FULL ENJOY - 9953040155 Call Girls in Sector 61 | Noida
FULL ENJOY - 9953040155 Call Girls in Sector 61 | NoidaFULL ENJOY - 9953040155 Call Girls in Sector 61 | Noida
FULL ENJOY - 9953040155 Call Girls in Sector 61 | NoidaMalviyaNagarCallGirl
 
GREEN VEHICLES the kids picture show 2024
GREEN VEHICLES the kids picture show 2024GREEN VEHICLES the kids picture show 2024
GREEN VEHICLES the kids picture show 2024AHOhOops1
 
What Causes DPF Failure In VW Golf Cars & How Can They Be Prevented
What Causes DPF Failure In VW Golf Cars & How Can They Be PreventedWhat Causes DPF Failure In VW Golf Cars & How Can They Be Prevented
What Causes DPF Failure In VW Golf Cars & How Can They Be PreventedAutobahn Automotive Service
 
UNIT-IV-STEERING, BRAKES AND SUSPENSION SYSTEMS.pptx
UNIT-IV-STEERING, BRAKES AND SUSPENSION SYSTEMS.pptxUNIT-IV-STEERING, BRAKES AND SUSPENSION SYSTEMS.pptx
UNIT-IV-STEERING, BRAKES AND SUSPENSION SYSTEMS.pptxDineshKumar4165
 
2024 WRC Hyundai World Rally Team’s i20 N Rally1 Hybrid
2024 WRC Hyundai World Rally Team’s i20 N Rally1 Hybrid2024 WRC Hyundai World Rally Team’s i20 N Rally1 Hybrid
2024 WRC Hyundai World Rally Team’s i20 N Rally1 HybridHyundai Motor Group
 
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一fjjwgk
 
(办理学位证)(Toledo毕业证)托莱多大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Toledo毕业证)托莱多大学毕业证成绩单修改留信学历认证原版一模一样(办理学位证)(Toledo毕业证)托莱多大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Toledo毕业证)托莱多大学毕业证成绩单修改留信学历认证原版一模一样gfghbihg
 
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样gfghbihg
 
定制多伦多大学毕业证(UofT毕业证)成绩单(学位证)原版一比一
定制多伦多大学毕业证(UofT毕业证)成绩单(学位证)原版一比一定制多伦多大学毕业证(UofT毕业证)成绩单(学位证)原版一比一
定制多伦多大学毕业证(UofT毕业证)成绩单(学位证)原版一比一meq5nzfnk
 
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhi
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhiHauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhi
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhiHot Call Girls In Sector 58 (Noida)
 
Call Girls in Karachi | +923081633338 | Karachi Call Girls
Call Girls in Karachi  | +923081633338 | Karachi Call GirlsCall Girls in Karachi  | +923081633338 | Karachi Call Girls
Call Girls in Karachi | +923081633338 | Karachi Call GirlsAyesha Khan
 
原版工艺美国普林斯顿大学毕业证Princeton毕业证成绩单修改留信学历认证
原版工艺美国普林斯顿大学毕业证Princeton毕业证成绩单修改留信学历认证原版工艺美国普林斯顿大学毕业证Princeton毕业证成绩单修改留信学历认证
原版工艺美国普林斯顿大学毕业证Princeton毕业证成绩单修改留信学历认证jjrehjwj11gg
 

Recently uploaded (20)

Beautiful Vip Call Girls Punjabi Bagh 9711199012 Call /Whatsapps
Beautiful Vip  Call Girls Punjabi Bagh 9711199012 Call /WhatsappsBeautiful Vip  Call Girls Punjabi Bagh 9711199012 Call /Whatsapps
Beautiful Vip Call Girls Punjabi Bagh 9711199012 Call /Whatsapps
 
VIP Kolkata Call Girl Kasba 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kasba 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kasba 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kasba 👉 8250192130 Available With Room
 
Call Girl Service Global Village Dubai +971509430017 Independent Call Girls G...
Call Girl Service Global Village Dubai +971509430017 Independent Call Girls G...Call Girl Service Global Village Dubai +971509430017 Independent Call Girls G...
Call Girl Service Global Village Dubai +971509430017 Independent Call Girls G...
 
Digamma - CertiCon Team Skills and Qualifications
Digamma - CertiCon Team Skills and QualificationsDigamma - CertiCon Team Skills and Qualifications
Digamma - CertiCon Team Skills and Qualifications
 
Indian Downtown Call Girls # 00971528903066 # Indian Call Girls In Downtown D...
Indian Downtown Call Girls # 00971528903066 # Indian Call Girls In Downtown D...Indian Downtown Call Girls # 00971528903066 # Indian Call Girls In Downtown D...
Indian Downtown Call Girls # 00971528903066 # Indian Call Girls In Downtown D...
 
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGER
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGERUNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGER
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGER
 
FULL ENJOY - 9953040155 Call Girls in Sector 61 | Noida
FULL ENJOY - 9953040155 Call Girls in Sector 61 | NoidaFULL ENJOY - 9953040155 Call Girls in Sector 61 | Noida
FULL ENJOY - 9953040155 Call Girls in Sector 61 | Noida
 
GREEN VEHICLES the kids picture show 2024
GREEN VEHICLES the kids picture show 2024GREEN VEHICLES the kids picture show 2024
GREEN VEHICLES the kids picture show 2024
 
What Causes DPF Failure In VW Golf Cars & How Can They Be Prevented
What Causes DPF Failure In VW Golf Cars & How Can They Be PreventedWhat Causes DPF Failure In VW Golf Cars & How Can They Be Prevented
What Causes DPF Failure In VW Golf Cars & How Can They Be Prevented
 
UNIT-IV-STEERING, BRAKES AND SUSPENSION SYSTEMS.pptx
UNIT-IV-STEERING, BRAKES AND SUSPENSION SYSTEMS.pptxUNIT-IV-STEERING, BRAKES AND SUSPENSION SYSTEMS.pptx
UNIT-IV-STEERING, BRAKES AND SUSPENSION SYSTEMS.pptx
 
2024 WRC Hyundai World Rally Team’s i20 N Rally1 Hybrid
2024 WRC Hyundai World Rally Team’s i20 N Rally1 Hybrid2024 WRC Hyundai World Rally Team’s i20 N Rally1 Hybrid
2024 WRC Hyundai World Rally Team’s i20 N Rally1 Hybrid
 
sauth delhi call girls in Connaught Place🔝 9953056974 🔝 escort Service
sauth delhi call girls in  Connaught Place🔝 9953056974 🔝 escort Servicesauth delhi call girls in  Connaught Place🔝 9953056974 🔝 escort Service
sauth delhi call girls in Connaught Place🔝 9953056974 🔝 escort Service
 
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一
 
(办理学位证)(Toledo毕业证)托莱多大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Toledo毕业证)托莱多大学毕业证成绩单修改留信学历认证原版一模一样(办理学位证)(Toledo毕业证)托莱多大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Toledo毕业证)托莱多大学毕业证成绩单修改留信学历认证原版一模一样
 
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样
 
定制多伦多大学毕业证(UofT毕业证)成绩单(学位证)原版一比一
定制多伦多大学毕业证(UofT毕业证)成绩单(学位证)原版一比一定制多伦多大学毕业证(UofT毕业证)成绩单(学位证)原版一比一
定制多伦多大学毕业证(UofT毕业证)成绩单(学位证)原版一比一
 
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhi
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhiHauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhi
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhi
 
Call Girls in Karachi | +923081633338 | Karachi Call Girls
Call Girls in Karachi  | +923081633338 | Karachi Call GirlsCall Girls in Karachi  | +923081633338 | Karachi Call Girls
Call Girls in Karachi | +923081633338 | Karachi Call Girls
 
原版工艺美国普林斯顿大学毕业证Princeton毕业证成绩单修改留信学历认证
原版工艺美国普林斯顿大学毕业证Princeton毕业证成绩单修改留信学历认证原版工艺美国普林斯顿大学毕业证Princeton毕业证成绩单修改留信学历认证
原版工艺美国普林斯顿大学毕业证Princeton毕业证成绩单修改留信学历认证
 
Call Girls In Kirti Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Kirti Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In Kirti Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Kirti Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 

Mbd2

  • 1. Rounding functions • Different function to round numbers: A = [-1.9, -0.2, 3.4, 5.6, 7.0, 2.4+3.6i] – fix(A) = [-1 0 3 5 7 2+3i] – ceil(A) = [-1 0 4 6 7 3+4i] -floor(A) = [-2 -1 3 5 7 2+3i] – round(A) = [-2, 0 3 6 7 2+4i]
  • 2. mod(X,Y) rem(X,Y) • Returns the remainder of X and Y • mod (x,0) =x • mod retains the sign of Y x mod y 11 mod 5 = 1 -11 mod 5 = 4 11 mod -5 = -4 -11 mod -5 = -1 • Returns the remainder of X and Y • rem(x,0)=NaN • rem retains the sign of X x rem y 11 rem 5 = 1 -11 rem 5 = -1 11 rem -5 = 1 -11 rem -5 = -1 George Iskander - ITI 2 Mathematical operation
  • 3. Matrix Indexing • B = A(1,1)  B = 1 • C = A(2,3)  C =2 • D = A(6)  D =9 • E = A(1, [1,2,3] )  A( 1st Row, Columns: 1,2 and 3) = 1 3 7 • F = A(1, : )  similar to A(1,1:3) = 1 3 7 • G = A(3 , 4) A(3rd Row, 4th Column)  Index exceeded matrix dimensions) • H = A( [1,3] , : )  A(Rows: 1 & 3 , All Columns) = [1 3 7; 8 90] • I = A(: , : )  A(All Rows, All Columns) = [1 3 7; -5 4 2; 8 90] • J = A(end,2)  A(Last Row,2) = 9 3
  • 4. Matrix Indexing • B = A( : )  A(Allelements) B = 1 -5 8 3 4 9 7 2 0 • D = A([2 3 1],[1 3 2 1]) D = -5 2 4 -5 8 0 9 8 1 7 3 1 4
  • 5. Matrix Indexing (Assigning Value) • A (1,1) = 5 • A(6) = 20 • A(1, [1,2,3] ) = [1 2 3] • A(3 , 4) = 7new column will be added • A( [1,3] , : ) = [4 7 4 1; 3 2 5 1] • A( [2,4] , [2,3] ) = -2.5*ones(2,2) new row will be added • A(end) = 78 ; A( 2, 1:end ) = [ 4 4 4 4] • A(end+1,end-1)=6 ; A(1:end,2:3)=[20 30;40 50;60 70;80 90;100 110] 5
  • 6. Eigen Values and Eigen Vectors Definition: A scalar λ is called an eigenvalue of the matrix A(n*n) where it is a nontrivial solution of A𝑥 = λ 𝑥. Such 𝑥 is called an eigenvector corresponding to the eigenvalue λ. A 𝑥 = λ 𝑥 A 𝑥 − λ 𝑥 = 0 A 𝑥 − λI 𝑥 = 0 (A − λI) 𝑥 = 0  det( A − λI) =0 Characteristic Equation of a system  Checkeig(A) 6
  • 7. For a multidimensional array • Enter a 3D matrix: – >> x = [1 2 3; 4 5 6; 7 8 9]; – >> x(:,:,2) = x’; • Check sum(x,1), prod(x,2) and mean (x,3) >> y = sum(x,1) >> y = prod(x,2) >> y = mean(x,3) y(:,:,1) = 12 15 18 y(:,:,2) = 6 15 24 y(:,:,1) = 6 120 504 y(:,:,2) = 28 80 162 y= 1 3 5 3 5 7 5 7 9 size(y) = 1 3 2 size(y) = 3 1 2 GesoirzgeeI(syka)nd=er3-I3TI 7
  • 8. A < B A <= B A > B A >= B A == B A ~= B • Returns a logical array 8
  • 9. • Logical Values: – Any nonzero value MATLAB consider as TRUE – Zero value MATLAB consider as FALSE – MATLAB always returns 1 as TRUE and 0 as FALSE • Short Circuit • && and || accept scalar values only.  For Conditions • For arrays (element-wise) & (and(A,B)) and | (or(A,B))  check >> 1.4 < sqrt(2) & [pi > 3 -1 > 1]  Scalar with vector • xor(A,B) , not(A) 9
  • 10. • MATLAB Fundamentals • Programming with MATLAB • MATLAB Toolboxes “Control Toolbox – Symbolic Toolbox” • Simulink • Data Type, Plotting and Fitting, Logical Index • Introduction to GUI • Extra :  Connecting Hardware with Matlab  Linking Matlab, Labview and Solidworks 10
  • 11. • Input and Output Commands  Text Interface  GUI Interface • Programming with MATLAB  M-file script and MATLAB function • Control Flow  If condition  Switch condition  For loop  While loop • Polymorphismic Function • Comment and Sections 11
  • 12. Text Interface • input()  Request user input >> prompt = ‘Enter the description of the required input’ >> result = input(prompt)  the input is stored as it is entered >> str = input(prompt,'s')  the input is stored as a string • If you press the Return key without entering anything, then input returns an empty matrix. 12
  • 13. Text Interface • disp() – display() :  disp(X) displays the X array, without printing thearray name. It 's the same as you write a statement without semicolon except that empty arrays don't display.  display(X) it differs from disp() that it displays the name of thevariable • MATLAB invokes the built-in display() when MATLAB executes a statement that returns a value and is not terminated with a semicolon. • MATLAB invokes the built-in disp function when the built-in display function calls disp. 13
  • 14. Text Interface • fprintf()  It is mainly used to write data to a file but we can use it to write to the screen directly. With addition property to control the format specification.  fprintf(FORMAT,A1,...,An) formats data and displays the results on the screen. FORMAT is a string that describes the format of the output fields, and can include combinations of the following: * Literal text to print. * Escape characters, including: b Backspace ‘ ‘ Single quotation mark f Form feed %% Percent character n New line Backslash r Carriage return t Horizontal tab 14
  • 15. Text Interface • fprintf() *Conversion specifications, which include a % character, a conversion character (such as d, i, o, u, x, f, e, g, c, or s), and optional flags, width, and precision fields. • Towrite on a file  fopen(), fclose() are used – fprintf(fileid, format, A1,…,An) 15
  • 16. Text Interface • error() Similar to fprintf; where a message in red appear on the command window as the default error message that is done by MATLAB and the code is terminated >> error('nX must be at least %4.2f mmn',5.634) X must be at least 5.63 mm  Check the difference with warning() 16
  • 17. GUI Interface • inputdlg() prompt = {'Enter your name:', 'Enter your age:'}; titlename =‘Personal Information'; numlines=1; default={‘Mahmoud Hussein',‘25'}; ANSWER = inputdlg(prompt, titlename, numlines, default) Example 2: x = inputdlg({'Name','Telephone',’Address’,'Account'}, … 'Customer Information ', [1 50; 1 12;2 50; 1 7]) Output is stored in cell array 17
  • 18. GUI Interface • menu() choice = menu('mtitle','opt1','opt2',...,'optn') choice = menu('mtitle',{'opt1','opt2',...,'optn‘}) Example: choice = menu('What is your department?', 'Java ', 'Mechatronics', 'GIS') Output is integer refering to the order of your choice 18
  • 19. GUI Interface • questdlg() button = questdlg('qstring','title')  By default (the choices are Yes, No and Cancel) button = questdlg(‘Is the course useful? ',‘Feedback',‘Yes',‘No', ‘May be‘, ‘Yes’) Output is a string similar to your choice 19
  • 20. GUI Interface Example:  Check listdlg How to do it? 20
  • 21. GUI Interface •msgbox() msgbox(message, title, icon) message=‘Help me’ title = Help icon= 'help‘ % It can be 'none', 'error', 'warn' or 'help'. The default is 'none' • errordlg() errordlg(message, title) • waitbar(x)  x varies from 0 to 1  Check warndlg(), helpdlg() 21
  • 22. George Iskander - ITI 22 • Any command written directly on the command window • Directly processed and the output will directly appear on the command window
  • 23. • Any command written directly on the command window • Directly processed and the output will directly appear on the command window 23
  • 24. M-file Script • A group of statements that are processed in sequence altogether. • These statements do a certain function. • No argument can be passed to the M-file before running • Has direct effect on the workspace • Before running the script, it must be save in an m-file *.m Conditions for choosing m-file name: Calling the script • Refers to the function of the script • Same as variables • Be sure no overlap with other built-in function. Check exist() • Press Run on the editor toolbar • Write the name of the m-file directly on the command window • Can be called inside other script 24
  • 25. M-file Script • Example 1: • Write an M-file that: – Plot a given function from user – Plot it’s derivative – Plot it’s integration – Identify the peaks and valleys of the main function • Used functions : cumtrapz() – plot() – text() – gtext() – title() 25
  • 27. M-file Script • Example 2: • Write an M-file that: – Plot a given function from user – Perform a limit integration according to the user input • Used functions : trapz() – area() – ginput() 27
  • 28. MATLAB Function • A group of statements that are processed in sequence altogether. • The first sentence must declare that the script is a function. Specify the inputs, outputs and the name of the function. • Argument can be passed to the function while calling it as well as assigning variables for outputs based on the prototype • Has its own workspace, (different scope) • Before running the function, it must be save in an m-file *.m with the same name of the function (same rules) Calling the Function • Press Run on the editor toolbar ,if no required arguments •Write the name of the function directly on the command window • Can be called inside other script 28
  • 29. MATLAB Function •Example 1: function myRand a= 5+rand(3,4)*2 end 1- We need a variable to hold the output of the function • Example 2: function a = myRand a= 5+rand(3,4)*2; end Activity 1: Check the value of • max(round(a)) • min(round(a)) • max(fix(a)) • min(fix(a)) You can find the variable ‘a’ in the workspace 29
  • 30. MATLAB Function 2- We need to declare variables to pass input to the function • Example 3: function a = myRand (low,high) a= low+rand(3,4)*(high-low); end 3- General form (accept no. of rows and coloums and the range) • Example 4: function a = myRand(row,col,low,high) a= low+rand(row,col)*(high-low); end The order of the input is very important 30
  • 31. MATLAB Function 4- We can have more than one output • Example 5a: function a = myRand(row,col,low,high) a = low+rand(row,col)*(high-low); a(end+1,end+1) = sum(a(:)); end Example 5b: function [a, sumno] = myRand(row,col,low,high) a = low+rand(row,col)*(high-low); sumno = sum(a(:)); end Compare both functions 31
  • 32. MATLAB Function 5- We can have more than one function • Example 6: function [a, sumno] = myRand(row,col,low,high) a = low+rand(row,col)*(high-low); sumno = sumelements(a(:)); end function x = sumelements(mat) x = sum(mat(:)); end Run it step by step and check the change in workspace 32
  • 35. Build the following function 1. Write a function called odd_index that takes a matrix, M, as input argument and returns a matrix that contains only those elements of M that are in odd rows and columns. Note that both the row and the column of an element must be odd to be included in the output. 2. Write a function called int_col that has one input argument, a positive integer n that is greater than 1, and one output argument v that is a column vector of length n containing all the positive integers from 1 to n, arranged in such a way that no element is equal to its own index value. 3. Write a function called pitty that takes a matrix called ab as an input argument. The matrix ab has exactly two columns. The function should return a column vector c that contains (a^2 + b^2)^0.5 = c, 35
  • 36. • if loop • switch case • for loop • while loop • try and catch 36
  • 37. if Loop • If the condition is true , a group of commands are executed, otherwise we jump to complete the rest of the program if (condition) -------- -------- end Commands Yes 37 No
  • 38. if - else Loop • If the condition is true , a group of commands are executed, otherwise another group of commands are executed then the rest of the program is completed normally if (condition) -------- -------- else -------- -------- end Commands 38 Yes No Commands
  • 39. Nested if Loop • If- elseif – else statement if (condition) -------- -------- elseif (condition) -------- -------- else -------- -------- end Commands Yes No Commands Commands Yes No Until the first 39 conditionis true
  • 40. switch case • Check the value of a variable, if it is equal to a certain value (case), the commands below it will be executed. • If no case is correct, a default block may be added at the end with a key word called otherwise switch x case 1 -------- case 2 -------- case 3 -------- otherwise -------- end Commands Commands Commands Commands Yes No Yes No Yes No In case you want more than one value in a case use { } 40
  • 41. for Loop • When you need to repeat a certain steps for a known number of times for i = 1:n -------- -------- end This loop will be repeated length of i times • A very strong feature that it can have variable step also it can be a cell array with different data types i= {‘hi’, *1:5], 3, [1:3;4:6]} Intialize Commands update Yes No 41
  • 42. while Loop • We you need to repeat a certain steps as long as a certain condition is true while (condition) -------- -------- end Commands Yes No 42
  • 43. break – continue - return 43 • break : Terminate execution of WHILE or FOR loop. – It will end the specified loop, will not complete the rest of iteration. If nested loops, will terminate the innermost loop only • continue : Pass control to the next iteration of FOR or WHILE loop without completing the current iteration, skipping any remaining statements in the body • return : when executed it returns to the invoking function – Normally functions return when the end of the function is reached. But a return statement can be used to force an early return.
  • 44. try and catch Type 1: Type 2: Explaination try -------- -------- end If error occurred the rest of the loop will not be completed without an error message try -------- -------- catch ME -------- -------- end • The statements between the try and catch are executed. However, if an error occurs while execution, the error is captured into an object, ME (optional) and the statements between the CATCH and END are executed. 44
  • 45. Try and catch >> A=input(‘Matrix=’); >>try >>B=inv(A); >>catch >>msgbox(‘matrix is not aquare’) >>end
  • 46. General Form • How to make our myrand function a polymorphism? • nargin  a variable that holds the number of input argument • nargout  a variable that holds the number of output argument • Implement it on myRand function to be generic function 46
  • 47. Variable I/P and Variable O/P • How to make a function that can have variable number of input or output? • function [s, varargout] = myfun(x, varargin) – varargin : Allows any number of arguments to a function. The variable varargin is a cell array containing the optional arguments to the function. It must be declared as the last input argument and collects all the inputs from that point onwards. – varargout : Allows any number of arguments out of a function. The variable varargin is a cell array containing the optional arguments of the function. It must be declared as the last output argument and must contains all the outputs after that point onwards 47
  • 48. % Toadd a comment. Anything after it will be ignored % If you write it under a declared function immediate , it will be the help of your function when you the user will ask for help %% In M-file, to run a separate part. 48