MATLAB tutorial by Dr Ben-Hamza

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

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

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 .

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

View Full Document
2 MATLAB Desktop Command Window Launch Pad History
3 MATLAB Desktop – cont’d Command Window Workspace Current DIrectory

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

View Full Document
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)
5 MATLAB Editor Color keyed text with auto indents tabbed sheets for other files being edited Access to commands

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

View Full Document
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
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 :

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

View Full Document
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);
9

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

View Full Document
10 How to use MATLAB? First test
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online