EE3350 Lecture MatlabIntro Yuan Hu
EE3350 Lecture MatlabIntro Yuan Hu
MATLAB INTRODUCTION
Instructor: Dr. Duncan MacFarlane
Teaching Assistant: Yuan Hu
WHAT IS MATLAB?
MATLAB is a numerical computing environment
developed by MathWorks.
MATLAB allows matrix manipulations, plotting of
functions and data, and implementation of
algorithms.
MatLab program and script files always have
filenames ending with ".m.
The programming language is exceptionally
straightforward since almost every data object is
assumed to be an array.
MATLAB WINDOWS
GETTING HELP
Online help is available from the Matlab prompt (a
double arrow)
generally (listing all available commands):
>> help
ARITHMETIC OPERATIONS
ARITHMETIC OPERATIONS
VECTOR OPERATIONS
Consider the vectors:
VECTOR OPERATIONS
Examples:
(1)Compute the dot product:
Logical Operators
CONTROL FLOW
.m files have the following control flow constructs:
if statements
for loops
while loops
Each of the constructs needs to terminate with an end
statement.
CONTROL FLOW
if: conditional execution of certain parts of a code
Example:
Matlab code:
Results:
CONTROL FLOW
for : repeat certain commands in a predetermined way
Example:
Matlab code:
Results:
CONTROL FLOW
while: repeats a sequence of commands as long as some
condition is met.
Example:
Matlab code:
Results:
Amplitude
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0.1
0.2
0.3
0.4
0.5
Time (s)
0.6
0.7
0.8
0.9
70
60
Amplitude
50
40
30
20
10
0
-80
-60
-40
-20
0
Frequency (Hz)
20
40
60
80
Amplitude
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0.1
0.2
0.3
0.4
0.5
Time (s)
0.6
0.7
0.8
0.9
50
Amplitude
40
30
20
10
0
-100
-80
-60
-40
-20
0
Frequency (Hz)
20
40
60
80
100
Amplitude
0.6
0.5
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
0.4
0.5
Time (s)
0.6
0.7
0.8
0.9
100
Amplitude
80
60
40
20
0
-100
-80
-60
-40
-20
0
Frequency (Hz)
20
40
60
80
100
cos(2S ( f1 f 2 )t ) cos(2S ( f1 f 2 )t )
2