Beruflich Dokumente
Kultur Dokumente
Lecture 1: Introduction
Lecture time:
Thursday 11:00 13:00
Course website:
http://www.weizmann.ac.il/midrasha/courses/MatlabIntro/
Team members
Lecturers:
Tutors:
Yuval Hart
Maya Geva
Exercise checkers:
Yuval Dorfan
Anat Tzimmer
Tips / formalities
Course website
http://www.weizmann.ac.il/midrasha/courses/MatlabIntro
Grade
Course references
Tips / formalities
Course overview
Introduction to Matlab
Loops
Debugger
GUI toolbox
Maya Geva:
21
10
21
73
21
18
21
10
21
21
10
45
21
21
10
11
12
Why Matlab?
Easy to learn
Easy to debug
13
14
Background - computers
Output
Input
15
Background - hardware
CPU
Memor
y
16
Background - software
High level languages
Examples: C, C++, C#, Java, Pascal, Perl, Lisp, Matlab
Low level language
Example: Assembly
Machine language
Example: 0111010101111101
Another important
player: The operating
system
17
18
Prompt / Command
line
Changing current
directory
The command
window
workspace
19
20
21
Comments
start with a %
(3) Defining script name
22
Making errors
23
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
24
Help!!!
help
doc
Example: docdisp
25
Matlab toolboxes
26
Introduction to Matlab
& Data Analysis
Topic #2:
The Matlab Building Blocks Variables, Arrays and Matrices
27
identifiers
Examples of Legal
identifiers:
time
day_of_the_week
bond007
findWord
Examples of illegal
identifiers:
007bond
#time
ba-baluba
if
while
28
Reserved
words
Library
functions
Constants
Variables
User
defined
functions
29
Reserved words
(keywords)
for
function
otherwise
try
break
end
return
switch
catch
if
elseif
continue
global
while
case
else
persistent
Constants
Numbers
100
0.3
Chars
c
Strings
Arrays
[12345]
Matrices
[5 3
4 2]
31
Variables
Computer memory
salary
9000
constant
new_salary
Example:
>>salary=9000;
>>new_salary=salary*3;
>>disp(new_salary);
27000
variable 27000
Library functions
32
Variables
Another example:
price_bamba=3
33
Variables
Another example:
price_bamba=3
n_bamba=2;
34
Variables
Another example:
price_bamba=3
n_bamba=2;
price_bisly=5
n_bisly=3;
total_price=price_bamba*n_bamba+price_bisly*n_bisly
n_bamba=5
total_price
35
Variables
36
Variables
Variables Types
>>a=10
a=
10
>>class(a)
ans=
double
Returns the
type of a
variable
The default variable
type in Matlab is
double
38
Variables Types
>>a=10
a=
10
>>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
39
Variables Types
>>a=10.4%doublerequires8bytes
a=
10.4
1
1 0 0 0 1 1 0 0
1 0 1 1 1 0 0 0
3
0 0 0 0 1 0 0 0
>>b='B'%charrequires2bytes
b=
B
12
1 0 0 0 1 1 0 0
1 0 0 0 1 0 0 0
Memory allocation
and release is done
automatically in
Matlab
1 0 1 1 1 0 0 0
40
Computer precision
limitations
How much is:
>> 0.42 + 0.08 - 0.5
ans =
0
41
Special variables
ans
>>4*5
ans=
20
>>ans+1
ans=
21
42
Special variables
ans
pi
inf
>>2*inf
ans=
Inf
>>1/0
Warning:Dividebyzero.
ans=
Inf
43
Special variables
>>0/0
Warning:Dividebyzero.
ans=
NaN
ans
pi
>>NaN+1
inf
ans=
NaN
NaN
In the tutorial youll see more
44
Summary
45