Introduction To Matlab
Introduction To Matlab
Introduction To Matlab
Lecture 1: Introduction
Lecture time:
Team members
Lecturers:
Tutors:
Exercise checkers:
Anat Tzimmer Ariel Gispan
Tips / formalities
Course material: Lectures + tutorials + other Matlab resources HW and solutions News
On any pc computer at Weizmann (installation of Matlab will be discussed in the first tutorial) In the tutorial class
Grade
Course references
Tips / formalities
Course overview
Introduction to Matlab
Math modeling of cancer treatment (Natalie) Protein production (Prof. Nir Friedman)
10
11
12
Why Matlab?
Easy to learn
Easy to debug
13
14
Background - computers
Output
Input
15
Background - hardware
CPU
Memory
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
workspace
19
20
21
Comments start with a % (3) Defining script name (4) Running the script
22
Making errors
Pressing here will bring you to the line in the script where the error occurred
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 % Play the movie twenty times movie(F,20)
5
-5
2 0 -2 y -3 -2 -1 x 0 1 2
24
Help!!!
help doc
25
Matlab toolboxes
26
Topic #2:
27
identifiers
Identifiers are all the words that build up the program An identifier is a sequence of letters, digits and underscores _ Maximal length of identifiers is 63 characters Cant start with a digit Cant be a reserved word Examples of illegal identifiers: 007bond #time ba-baluba if while
28
Reserved words
Library functions
Constants
Variables
29
Do NOT try to redefine their meaning! Don NOT try to redefine their library function names either!
30
Constants
The value of a constant is fixed and does not change throughout the program
Chars
c
Numbers
100 0.3
Strings Arrays
[12345] I like to eat sushi 1 + 2
Matrices
[5 3 4 2]
31
Variables
Computer memory
salary 9000
constant
new_salary
Example:
27000
variable
Variables
Another example:
price_bamba = 3
33
Variables
Another example:
34
Variables
Another example:
= = = = 3 2; 5 3;
total_price = 21
n_bamba = 5
total_price = 21
35
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;
36
Variables
When should I use capital letters ? Tip #3: Whatever you do - be consistent.
37
Variables Types
Variables Types
Variables Types
3
0 0 0 0 1 0 0 0
8
1 0 0 0 1 0 0 0
1 0 0 0 1 1 0 0
>> b = 'B' b = B 1
%char requires 2 bytes Memory allocation and release is done automatically in Matlab
2
1 0 1 1 1 0 0 0
1 0 0 0 1 1 0 0
40
41
Special variables
ans
42
Special variables
ans pi inf
>> 2 * inf ans = Inf >> 1 / 0 Warning: Divide by zero. ans = Inf
43
Special variables
ans pi >> NaN + 1 inf ans = NaN NaN In the tutorial youll see more
44
Summary
45