starting Matlab-Ling Peng

starting Matlab-Ling Peng - Generated by Foxit PDF Creator...

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

View Full Document Right Arrow Icon
EE 103 Spring 2010 Ling Peng 1 starting MATLAB 2 Variables: matrix, vector and scalar A=[1 2 3 4;5 6 6 8;9 10 11 12] A = 1 2 3 4 5 6 6 8 9 10 11 12 A=[1 2 3 4;5 6 7 8;9 10 11 12] A = 1 2 3 4 5 6 7 8 9 10 11 12 We don’t need to retype the entire matrix, we may simply change the element using its row and column indices. (We can always access and change an element in a matrix or vector like this) A(2,3)=7 Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.
Background image of page 1

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

View Full DocumentRight Arrow Icon
You can also refer to a specific row or column in a matrix, the second column of matrix A can be accessed by typing: >> A(:,2) ans = 2 6 10 And the second row of A can be accessed by typing: >> A(2,:) ans = 5 6 7 8 MATLAB allows another means of generating row vectors having constant increments . The convention is; Variable = minimum element : increment : maximum element Therefore typing; >> x=1:0.1:2 Result in: x = 1.0000 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000 Note : when making multiplication, make sure that the dimensions are match. >>x=1:5; >>y=2:0.5:4; If you type: >> x*y ??? Error using ==> mtimes Inner matrix dimensions must agree. If you type: >> x.*y %element-wise multiplication ans = 2 5 9 14 20 It may not be desirable for MATLAB to display every result, then you can just add a semicolon at Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.
Background image of page 2
the end of a line. For example >>B=[1 2; 3 4]; Doesn’t generate any display on the screen. However the 2 by 2 matrix is saved in MATLAB for subsequent use. To verify this, you can type: >> B Then this result in: B = 1 2 3 4 Variable names start from a letter and can be formed by any letters and digits. Note that MATLAB is case-sensitive, i.e.-it distinguishes between uppercase and lowercase letters. 3 Some MATLAB operations and functions We can perform arithmetic with vectors and matrices the same way as we did with scalars. The following list defines some of the operators available in MATLAB:
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

starting Matlab-Ling Peng - Generated by Foxit PDF Creator...

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

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