MATLAB tutorial by Dr Ben-Hamza

MATLAB tutorial by Dr Ben-Hamza - 1 What is MATLAB? MATLAB...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
1 What is MATLAB? On both system leave a MATLAB session by typing : >> quit or by typing >> exit at the MATLAB prompt. PC - a double click on the MATLAB icon on your desktop MATLAB is a commercial "Matrix Laboratory" package which operates as an interactive programming environment. MATLAB is well adapted to numerical experiments. MATLAB program and script files ( m-files ) always have filenames ending with " .m "; The programming language is exceptionally straightforward since almost every data object is assumed to be an array. Graphical output ( figure ) is available to supplement numerical results. Online help is available from the MATLAB prompt (a double arrow) by typing help .
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 MATLAB Desktop Command Window Launch Pad History
Background image of page 2
3 MATLAB Desktop – cont’d Command Window Workspace Current DIrectory
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 MATLAB Programs MATLAB is an extravagant calculator if all we can do is execute commands typed into the Command Window… So how can we execute a “program?” Programs in MATLAB are: Scripts , or Functions Scripts : MATLAB statements that are fed from a file into the Command Window and executed immediately Functions : Program modules that are passed data (arguments) and return a result (i.e., sin(x)) These can be created in any text editor (but MATLAB supplies a nice built- in editor)
Background image of page 4
5 MATLAB Editor Color keyed text with auto indents tabbed sheets for other files being edited Access to commands
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Algebraic operations in MATLAB: Scalar Calculations: + addition - subtraction * multiplication / right division (a/b means a ÷ b) \ left division (a\b means b ÷ a) ^ exponentiation For example >> 3*4 executed in ‘MATLAB' gives ans=12 >> 4/5 gives ans=.8 >> 4\5 ans=1.25 >> x = pi/2; y = sin(x) y = 1
Background image of page 6
7 Colon operator: The colon operator ' : ' is understood by MATLAB to perform special and useful operations. • For example, if two integer numbers are separated by a colon, MATLAB will generate all of the integers between these two integers. a = -2:5 generates the row vector, a = [ -2 -1 0 1 2 3 4 5 ]. • If three numbers, integer or non-integer, are separated by two colons, the middle number is interpreted to be a ”step" and the first and third are interpreted to be "limits”: b = 0.0 : .2 : 1.0 generates the row vector b = [ 0.0 .2 .4 .6 .8 1.0 ] Syntax in MATLAB :
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Some basic commands you may need: figure creates an empty figure window close by itself, closes the current figure window plot plot a graph >> x=0:.01:2*pi; y=sin(x); plot(x,y); grid; >> xlabel('x'); ylabel('y=sin(x)'); stem plot a data sequence >> n=-5:5; x = (n>=0); stem(n,x); grid; >> xlabel('n'); ylabel('x[n]=u[n]') >> set(gca, 'XTick', n);
Background image of page 8
9
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 How to use MATLAB? First test
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 48

MATLAB tutorial by Dr Ben-Hamza - 1 What is MATLAB? MATLAB...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online