matlab_zakl_sig_e
TRANSCRIPT
-
8/3/2019 matlab_zakl_sig_e
1/3
Introduction to MatLab and basic operations with signalsJan Cernocky, FIT VUT Brno
MATLAB (MATrix LABoratory) software for scientific computation and visualization.
1 Some hints: after the start of Windows, run Matlab from Q:\matlab6p1 by double-clicking on its icon. Ignore the error messages.
in Matlab, commands can be entered only in case the cursor is on the command line: >>
run any text editor in another window you may use also built-in editor of Matlab, that can make Matlab codemore beautiful (colors, etc.). In this editor, open a text file, where youll write everything (commands, results, yourcomments). The commands can be copied to Matlab using standard copy-paste (Ctrl-c Ctrl-v) sequence. After theend of the lab, youll have an exact log of what you did and what (hopefully) worked.
In case the Matlab line contains %, everything after this character is considered as a comment and is not interpreted.
in Matlab, you can return to previous commands using the arrow key . The return can be also selective, for
example, you can return to already typed plot-commands by: pl . . .
2 Basic functionalities of Matlab
1. Variables:
scalar: a=1;
column vector: vecsl=[1; 2; 3]
row vector: vecrad=[2.5 16e-3 85]
matrix: mat=[1 2 3; 4 5 6; 7 8 9]
2. Visualization of variables contents:
text: the name of the variable without semicolon+Enter.
graphical with x-coordinates equal to indices of elements 1,2,3,. . . : plot(vec)
graphical with both x- and y-coordinates: plot(vecx,vecy)
size of a variable:length(vec) length of a vectorsize(mat) number of rows and columns of a matrix (2-point vector).
3. Help !!!
help name of function
lookfor keyword
4. Case sensitivity: in names of variables, Matlab is like C:myvector = Myvector = MYVECTOR.
Exercises
1. Fill scalar, vector and matrix variable. Visualize their contents as text and graphically.
2. How do you enter a complex number ? Whats the result of visualization of complex numbers ?
3 Basic operations with vectors and matrices
addition/subtraction/multiplication/division vector or matrix vs. scalar: v+s, v-s, v*s, v/s
scalar product (inner product) of two vectors: line v*col v
multiplication of two vectors point-by-point (dot-product): line v.*line v, col v.*col v, mat.*mat
generation of an arithmetic sequence with step 1: min value:max valuewith arbitrary step: min value:step:max value
1
-
8/3/2019 matlab_zakl_sig_e
2/3
transpose of a vector/matrix: vector, matrix
functions (abs, sin, cos, log,. . . ) work mostly also with vectors and matrices point-by-point.
zero- and unity-matrices:zeros(number rows,number columns), ones(number rows,number columns)
accessing elements of vectors and matrices: vec(1), vec(2:5), mat(3,4), mat(3,:), mat(1:5,4)
finding indices of vector/matrix satisfying a condition: find, for example: n = -10:10; ii = find(n=-1 & t
-
8/3/2019 matlab_zakl_sig_e
3/3
t = -10:0.01:10;
tplus2 = t+2;
splus2 = zeros(size(tplus2));
splus2(find(tplus2>=-1 & tplus2