Lecture 1 - Introduction To Matlab
Lecture 1 - Introduction To Matlab
Lecture 1: Introduction
Lecture time:
Team members
Lecturers:
Tutors:
Maya Geva
Anat Tzimmer
Yuval Hart
Exercise checkers:
Gil Farkash
Tips / formalities
Course website
http://www.weizmann.ac.il/midrasha/courses/MatlabIntro
The website contains
Grade
Course references
Tips / formalities
Course overview
Introduction to Matlab
Loops
Debugger
GUI toolbox
21
10
21
73
21
18
21
10
21
21
10
45
21
21
Image processing
10
11
12
Why Matlab?
Easy to learn
Easy to debug
13
14
Background - computers
Output
Processing unit
Input
15
Background - hardware
CPU
Memory
16
Background - hardware
CPU
Memory
Not to be confused with the hard disk which is used to store data.
17
Background - software
High level languages
Examples:
Example: 0111010101111101
Another important player:
The operating system
18
19
workspace
20
21
22
Comments start
with a %
(3) Defining script name
23
Making errors
24
Another script
Making sophisticated graphics and animation in Matlab is easy.
We will learn how to do this in two lectures
Peaks
Z = peaks; surf(Z);
axis tight
set(gca,'nextplot','replacechildren');
% Record the movie
for j = 1:20
surf(sin(2*pi*j/20)*Z,Z)
F(j) = getframe;
end
-5
2
0
-2
y
-3
-2
-1
25
Help!!!
help
doc
26
Matlab toolboxes
27
Introduction to Matlab
& Data Analysis
Topic #2:
28
identifiers
Examples of Legal
identifiers:
time
day_of_the_week
bond007
findWord
Examples of illegal
identifiers:
007bond
#time
ba-baluba
if
while
29
Reserved
words
Library
functions
Constants
Variables
User defined
functions
30
for
function
otherwise
try
break
end
return
switch
catch
if
elseif
continue
global
while
case
else
persistent
31
Constants
Numbers
100
0.3
Chars
c
Strings
Arrays
[12345]
Matrices
[5 3
4 2]
32
Variables
Computer memory
salary
9000
constant
new_salary
variable
27000
Example:
If we update salary,
new_salary will NOT
be updated
automatically
33
Variables
Another example:
price_bamba = 3
34
Variables
Another example:
price_bamba = 3
n_bamba
= 2;
35
Variables
Another example:
price_bamba
n_bamba
price_bisly
n_bisly
=
=
=
=
3
2;
5
3;
price_bamba =
3
price_bisly =
5
total_price =
21
n_bamba =
5
total_price =
21
How can
we fix it?
36
Redefine total_price
total_price = price_bamba * n_bamba + price_bisly * n_bisly
n_bamba
= 5
total_price
Variables
are a bad choice for naming variables that store your working hours
and salary!
A more meaningful choice of names would
salary = 9000;
hours = 5;
37
Variables
38
Variables Types
Variables Types
Double
40
Variables Types
>> b = 10.56
b =
10.5600
>> c = 'Bush'
c =
Bush
>> d = true
d =
1
>> class(a)
ans =
double
>> class(b)
ans =
double
>> class(c)
ans =
char
>> class(d)
ans =
logical
41
Variables Types
1 0 0 0 1 1 0 0
>> b = 'B'
b =
B
1 0 1 1 1 0 0 0
0 0 0 0 1 0 0 0
1 0 0 0 1 0 0 0
1
1 0 0 0 1 1 0 0
1 0 1 1 1 0 0 0
42
43
Special variables
ans
>> 4 * 5
ans =
20
>> ans + 1
ans =
21
44
Special variables
ans
pi
inf
>> 2 * inf
ans =
Inf
>> 1 / 0
Warning: Divide by zero.
ans =
Inf
45
Special variables
>> 0 / 0
Warning: Divide by zero.
ans =
NaN
ans
pi
>> NaN + 1
inf
ans =
NaN
NaN
In the tutorial youll see more
46
Summary
47
Floating point
48
Assuming that the best resolution is in light years, only the 9 most
significant decimal digits matter, whereas the remaining 30 digits carry
pure noise, and thus can be safely dropped. This represents a savings
of 100 bits of computer data storage. Instead of these 100 bits, much
fewer are used to represent the scale (the exponent), e.g. 8 bits or 2
decimal digits. Given that one number can encode both astronomic and
subatomic distances with the same nine digits of accuracy, but because
a 9-digit number is 100 times less accurate than the 11 digits reserved
for scale, this is considered a trade-off exchanging range for precision.
The example of using scaling to extend the dynamic range reveals
another contrast with fixed-point numbers: Floating-point values are
not uniformly spaced. Small values, close to zero, can be represented
with much higher resolution (e.g. one femtometre) than large ones
because a greater scale (e.g. light years) must be selected for
encoding significantly larger values.[1] That is, floating-point numbers
cannot represent point coordinates with atomic accuracy at galactic
distances, only close to the origin.
49
Floating point
The term floating point refers to the fact that a number's radix point
(decimal point, or, more commonly in computers, binary point) can
"float"; that is, it can be placed anywhere relative to the significant
digits of the number. This position is indicated as the exponent
component in the internal representation, and floating point can thus
be thought of as a computer realization of scientific notation.
50