Beruflich Dokumente
Kultur Dokumente
Part-1
Entering Matrices
Subscripts
To generator vector
Unit steps startvalue:endvalue
Nonunit steps with the given increment
startvalue:stepvalue:endvalue
Generating Matrices
Zeros
Ones
Generating Matrices
10
Concatenation
11
12
Reordering data
13
Changing data
14
Arrays
Array: N dimensional
15
Multidimensional Array
16
17
Matrix Algebra
Addition
Subtraction
Matrix multiplication
Array multiplication
18
Addition
+
A and B must have the same size, unless one of them is
a scalar
19
Subtraction
20
Matrix Multiplication
21
Array Multiplication
.*
element-by-element product of the arrays A and B
A and B must have the same size, unless one of them is
a scalar
22
Part 2
23
Expressions
Variables
Numbers
Operators
Functions
24
Numbers
6.02252e23
25
Functions
26
Data Types
27
Numeric Types
28
Floating-Point Numbers
29
Complex Numbers
>> x = 2 + 3i
x=
2.0000+3.0000i
>> z = complex(2.1, pi)
z=
2.1000 + 3.1416i
>> zr = real(z)
zr =
2.1000
>> zi = imag(z)
zi =
3.1416
30
Infinity
x = log(0);
>> isinf(x)
ans =
31
5-digit scaled fixed point, floating point, or the best of the two
15-digit scaled fixed point, floating point, or the best of the two
A ratio of small integers
Hexadecimal (base 16)
Bank notation
32
Format
x = [4/3 1.2345e-6]
x=
1.3333
0.0000
format short e
x
x=
1.3333e+000
1.2345e-006
format long
x
x=
1.33333333333333
0.00000123450000
copyright Durga Lal Shrestha
33
Logical Types
Vector of logical
[30 40 50 60 70] > 40
ans =
00111
34
Logical Types
35
Logical Indexing
36
Part 3
37
Bytes
10
Class
char
Attributes
38
Padding.
39
Structure Array
40
Structure Array
41
Structure Array
42
Cell Arrays
43
Cell Arrays
44
Part 4
Data Import and Export
45
46
Save and load command for both ASCII and Mat file
47
Load command
48
Part 5
MATLAB Graphics
49
Matlab Graphics
Plotting Process
Graph Components
Figure Tools
Arranging Graphs Within a Figure
Selecting Plot Types
50
Plotting Process
51
Graph Components
Figure
Plot
Axis
Data
52
53
54
55
56
Plotting Steps
57
OR
plot(x,y)
hold on
plot(x,sin(x-0.5),'r')
plot(x,sin(x-0.25),'g')
58
plot(x,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
59
Contour plots
-1
-2
-3
-3
-2
-1
60
Contour
61
Contour3
10
-5
-10
2
0
-2
-3
copyright Durga Lal Shrestha
-2
-1
62
3D plot
Plot3 command
63
64
100
200
300
400
500
600
100
200
300
400
500
65
Surface plot
0.5
-0.5
10
5
10
5
-5
-5
-10
-10
66
Surface plot
67
68
Part 6
Program components
69
Variables
Keywords
Special Values
Operators
MATLAB Expressions
Program Control Statements
Symbol Reference
MATLAB Functions
70
Variables
71
Naming Variables
72
Keywords
'break
'catch
'else
'end
'function
'if
'persistent
'switch
'while'
'case'
'continue'
'elseif'
'for'
'global'
'otherwise'
'return'
'try'
73
Special Values
74
Operators
Arithmetic Operators
Relational Operators
Logical Operators
75
Arithmetic Operators
76
Relational Operators
77
Logical Operators
78
Operator Precedence
Parentheses ()
Transpose (.'), power (.^), complex conjugate transpose (), matrix
power (^)
Unary plus (+), unary minus (-), logical negation (~)
Multiplication (.*), right division (./), left division (.\), matrix
multiplication (*), matrix right division (/), matrix left division (\)
Addition (+), subtraction (-)
Colon operator (:)
Less than (<), less than or equal to (<=), greater than (>), greater
than or equal to (>=), equal to (==), not equal to (~=)
Element-wise AND (&)
Element-wise OR (|)
Short-circuit AND (&&)
Short-circuit OR (||)
79
Scripts
Scripts are the simplest kind of M-file because they have no
input or output arguments.
They are useful for automating series of MATLAB commands.
They operate on data in the workspace.
80
81
Conditional Control if
if logical_expression
statements
end
if logical_expression1
statements1
elseif logical_expression2
statements2
else
statements3
end
82
83
statements
end
84
85
86
87
88
89
Part 7
Symbol Reference
90
Symbol Reference
At @
for fhandle = @myfun
Colon :
Comma ,
Curly Braces { }
Dot .
Dot-Dot-Dot (Ellipsis) ... on page 3-103
Exclamation Point ! for Shell Escape (e.g. !dir)
Parentheses ( ) for array indexing and function input arguments
Percent % and Percent-Brace %{ %}
Semicolon ;
Single Quotes for character and string
Space Character
Square Brackets [ ]
91
Colon :
92
Comma ,
93
Curly Braces { }
94
Dot .
95
Line Continuation
96
Conversion Specifiers
Block Comments
97
Semicolon ;
Output Suppression
98
Space Character
99
Square Brackets [ ]
Array Constructor
Concatenation
100
Part 8
M-File Programming
101
102
103
Functions
help fmagicrank
type mr = fmagicrank(10);
104
105
106
function c = myfunc(a,b)
c = sqrt((a.^2)+b.^2))
x = 7.5;
y = 3.342;
z = mufunc(x,y)
z=
8.2109
107
Types of Functions
108
109
Nested Functions
110
Subfunctions
111
Exercise Function
function [Y] = filterdata(data,thres)
[NRow,NCol]=size(data);
j=1;
Y=[];
for i=1:NRow
if data(i)>=thres
Y(j)=data(i);
j=j+1;
end;
end;
112
Function Handles
113
Function Functions
Zero finding
Optimization
Quadrature
Ordinary differential equations
114
Humps function
115
hold on;
plot(p,humps(p),'r*');
116
117
Q = quadl(@humps,0,1)
Q=
29.8583
Z = fzero(@humps,0.5)
Z=
-0.1315
Z = fzero(@humps,1)
Z=
1.2955
f = humps(Z)
f=
0
118
Part 9: GUIDE
Simple Graphical User Interface
119
GUIDE
120
121
122
123
124