Professional Documents
Culture Documents
Matlab Thai PDF
Matlab Thai PDF
MATLAB
3
GUI
text
MATLAB MATLAB 5.3
Release 11 MATLAB MATLAB 6.0 Release 12 MATLAB
GUI
MATLAB 6.0 GUIDE
GUI
GUI GUIDE
1
MATLAB MATLAB
MALLAB Desktop
Cell Array Structure 2
version 5.0
12 15
GUI MATLAB Visual MATLAB
Graphic MATLAB 12 object MATLAB
13 Object 14 GUIDE
GUI 15 GUI
1 MATLAB _________________________________________1
1.1 ______________________________________________________________ 1
1.2 MATLAB ________________________________ 3
1.3 MATLAB___________________________________________________ 6
1.4 _________________________________________________________ 14
1.5 _______________________________________________________________ 19
2 MATLAB ________________________________________20
2.1 Scalars, Vectors and Matrices _______________________________________ 20
2.2 Matrix Operation_______________________________________________________ 27
2.3 Matrix Functions _______________________________________________________ 29
2.4 Multidimensional Arrays__________________________________________________ 37
2.5 Cell Arrays ___________________________________________________________ 39
2.6 Structures ___________________________________________________________ 43
2.7 Output Options ________________________________________________________ 45
2.8 Simple Plot __________________________________________________________ 47
" ________________________________________________ 57
10 SYMBOLIC MATHEMATICS_____________________________________160
10.1 Symbolic Algebra ____________________________________________________ 160
10.2 Equation Solving _____________________________________________________ 165
10.3 Differentiation Integration___________________________________________ 168
10.4 Symbolic Transformation_______________________________________________ 170
10.5 Function Calculator ___________________________________________________ 173
10.6 Symbolic Math Toolbox : Student Edition ____________________________ 177
11 M-BOOK__________________________________________________180
11.1 M-book _____________________________________________________ 180
11.2 ___________________________________________________ 181
11.3 Input & Output Cells __________________________________________________ 182
11.4 Notebook Menu ___________________________________________ 187
11.5 M-book Template ______________________________ 188
14 GUIDE________________________________________243
14.1 GUI GUIDE________________________________________________ 243
14.2 GUI MATLAB _________________________________________ 244
14.3 Application M-file GUIDE______________________________________ 248
14.4 _______________________________ 256
14.5 User Interface Controls ________________________________________________ 262
14.6 Understanding the Application M-File ______________________________________ 262
14.7 GUI__________________________________________ 267
14.8 GUI ____________________________________________ 269
14.9 ________________________________________________________ 270
15 GUIDE ____________________________________________271
15.1 Radio Button _____________________________________________ 271
15.2 Slider Editable Text __________________________________________ 279
15.3 Check Box, List Box Popup Menu _______________________________ 282
15.4 Object Handle GUI _______________________________ 287
MATLAB________________________________________________ 295
____________________________________________________________ 306
1 MATLAB
1.1
MATLAB MATLAB
MATLAB
MATLAB (Interactive)
MATLAB
MATLAB
array (
element ) array MATLAB dimension
matrix vector
C Fortran
MATLAB
MATLAB MATrix LABoratory MATLAB
Matrix MATLAB
Dr. Cleve Molor Fortran
LINPACK EISPACK
MATLAB C MathWorks
LAPACK ARPACK
MATLAB
matrix
..2000 MATLAB 6.0
Introduction to MATLAB 1
12 MATLAB
MATLAB
C Fortran
MATLAB
MATLAB MathWorks MATLAB
toolbox MATLAB
Toolbox
MATLAB
toolbox
signal processing, control systems, neural networks, fuzzy logic, wavelets, simulation
MATLAB
MATLAB
Math Works High-Performance
Numeric Computation and Visualization Software
MATLAB
MATLAB function
function function
MATLAB
C, FORTRAN
MATLAB 2 3
MATLAB Dynamic Link Word, Excel
windows
MATLAB toolbox function
MATLAB
2 Basic Operation
MATLAB
MATLAB MATLAB
MATLAB
Help MATLAB
Internet
http://www.mathworks.com
1.2 MATLAB
n MATLAB
MATLAB MATLAB
5
1. Development Environment.
4. Handle Graphics
Development Environment
graphical user interface MATLAB Desktop Command
Windows, command history browsers help, workspace, files search path
Introduction to MATLAB 3
The MATLAB Mathematical Function Library
Algorithms
sine, cosine
inverse matrix eigenvalues eigenvector
fast Fourier transforms
Handle Graphics
image processing
Graphic User Interface MATLAB
o MATLAB
Windows
MATLAB shortcut MATLAB desktop
Start MATLAB
Programs Windows
4 Basic Operation
MATLAB 6 MATLAB desktop
MATLAB MATLAB
desktop
Launch Pad
toolbox MATLAB
desktop
desktop (docking)
desktop desktop shortcut
context menus desktop
Preferences File Command
Window desktop Help
Preferences
Introduction to MATLAB 5
1.3 MATLAB
MATLAB 6.0 Version MATLAB
MATLAB desktop
version 6 MATLAB
MATLAB
desktop MATLAB 6
MATLAB Desktop 5 Command Windows,
Command History Window, Current Directory Browser, Workspace Browser Launch Pad
n Command Window
Command Window MATLAB
version MATLAB
MATLAB
6 Basic Operation
Command History
MATLAB
-
(Delete Selection) (Delete to Selection)
(Delete Entire History)
Command Windows
M-file
Shift
Create M-File Editor M-file
M-file
Introduction to MATLAB 7
Current Directory
Current Directory Desktop Toolbar
Current Directory
Current Directory
directory Current Directory
Current Directory directory Browser
directory file
Windows
file
MATLAB Current Directory Browser desktop tool current
Directory Browser
8 Basic Operation
Search Part
Command Window Function
Search Path Search Path
directory MATLAB directory MATLAB
MATLAB Toolbox Search Path
Search Path Set Path
File Menu directory Search Path
directory Search Path path
MATLAB Command Prompt
path
MATLABPATH
C:\MATLABR12\toolbox\MATLAB\general
C:\MATLABR12\toolbox\MATLAB\ops
..
C:\MATLABR12\toolbox\wavelet\wavedemo
C:\MATLABR12\toolbox\rtw\targets\xpc\target\kernel\embedded
C:\MATLABR12\work
p Workspace Browser
MATLAB
(Workspace) MATLAB
M-file load
MATLAB 6.0 Workspace Browser
Desktop Tool version MATLAB who whos
Command Windows Workspace Browser
Introduction to MATLAB 9
Workspace Browser array workspace
workspace Browser Workspace
Delete Selection
array
( )
cell cell
Open Selection
Array Editor
space sheet Matrix Matrix
array editor
10 Basic Operation
Array Editor ()
cell cell Array Editor
array size
cell
undo
q Launch Pad
Launch Pad toolbox
MATLAB Toolbox
Launch Pad file Windows Explorer
Toolbox
Launch Pad
Introduction to MATLAB 11
5 MATLAB Desktop
Desktop undock
(Command Windows)
Desktop Dock View
desktop
Desktop
View
Desktop Preference File
r Editor/Debugger
M-file Text Editor Notepad
M-file ASCII Code MATLAB
version 5 editor MATLAB
editor debugger
Editor/Debugger M-files
MATLAB Editor/Debugger text
editor Debugger
MATLAB
12 Basic Operation
MATLAB file M-file
Editor/Debugger
Editor/Debugger
Editor/Debugger
M-file
s Graphic Windows
MATLAB Graphic Windows
Graphic Window
MATLAB Menu Bar Graphic Window
Introduction to MATLAB 13
Graphical User
Interface
windows Graphic Window
version MATLAB
Graphic Window
version 6
fit curve Graphic Window
Graphic Window Graphic
1.4
MATLAB
MATLAB
MATLAB Command Window
MATLAB
14 Basic Operation
MATLAB
input MATLAB Courier New
Airtime = B*C(1,2)
output MATLAB Courier New
Airtime = 20
% comment MATLAB
^ MATLAB
Enter key ( Enter
key )
o MATLAB
quit exit MATLAB
clear
save disk
MATLAB
Ctrl c
^ MATLAB function
p Function Keys
MATLAB keys
Introduction to MATLAB 15
Ctrl-p
Ctrl-n
Ctrl-f 1
Ctrl-b 1
Del Backspace 1
Ctrl-l Ctrl- 1
Ctrl-r Ctrl- 1
Ctrl-a Home
End
Ctrl-k
q
MATLAB
help
16 Basic Operation
Help Help Browser
MATLAB Help
html Browser
( install ) Help browser
help
r Using MATLAB
Development Environment MATLAB desktop
Mathematics
MATLAB
Programming and Data Types MATLAB
Graphics
MATLAB
3-D Visualization view lighting
3
Introduction to MATLAB 17
External Interfaces/API C
Fortran Java, , serial port I/O, ActiveX DDE
Creating Graphical User Interfaces
MATLAB graphical user interface
s Reference
MATLAB Function Reference MATLAB
syntax
Function
By Category Alphabetical List of Functions
External Interfaces/API Reference MATLAB
MATLAB
t MATLAB Demos
Toolbox
MATLAB
MATLAB
demo
demo
Run. MATLAB
18 Basic Operation
1.5
MATLAB
3 MATLAB
MATLAB MATLAB 6
Introduction to MATLAB 19
2 MATLAB
MATLAB
underscore ( _ )
MATLAB
19
MATLAB case-sensitive variable
xA, xa, XA
n
assignment statement =
A 1
A = 1
20 Basic Operation
vector matrix [ ]
(row) elements row
(space) comma
A = [1, 2, 3]
A = [1 2 3]
MATLAB
A =
1 23
row
enter
a =[1, 2
3, 4]
a matrix [1 x 6]
Basic Operation 21
b b = [0 1 2 3]
MATLAB (echo)
a = [1, 2, 3]
MATLAB
a =
1 2 3
MATLAB semi-
colon
a = [1, 2, 3];
echo
MATLAB ans
0 MATLAB
echo echo
matrix a
a =
1 5
3 4
a(3) = 5
a
a = [1 2 5]
22 Basic Operation
a = [1 2 3] a(7) = 5 a
a = [1 2 0 0 0 0 5]
MATLAB 3
who
whos , byte
size matrix array a = 13 2
4
,
size(a)
ans =
2 2
o Colon operator
Colon operator operator matrix
vector matrix
x = [1 2 3; 4 5 6; 9 10 0];
a column 1 x
a = x(:, 1)
a =
1
4
9
b = x(2,:) b row 2 x
b = [4 5 6]
Basic Operation 23
colon 3 2
3
k = 1:0.5:5 row vector
k = [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
colon
k = 5:-0.5:1
k = [5, 4.5, 4, 3.5, 3, 2.5, 2, 1.5, 1]
c = a(1:2,1)
c =
1
4
d = a(:,2:3)
d =
2 3
5 6
7 8
24 Basic Operation
6
8
1 4
1 2 3
a= a = 2 5
T
4 5 6 3 6
b = a'
b =
1 4
2 5
3 6
p
1 1
a = [1 2 3];
a = [3 4];
MATLAB a = [3 4]
a = [1 2 3];
a = [5 a];
MATLAB
A = [5 1 2 3];
q MATLAB
MATLAB
pi 3.14159
i j imaginary valve 1
Basic Operation 25
Inf infinity
NaN Not-a-Number (undefined) 0 0
clock Computer
date format -- 1-jan-97
eps floating-point precision computer
ans
r Matrix MATLAB
Matrix MATLAB matrix
26 Basic Operation
square matrix m n
ones(2) matrix 11 1
1
a=eye(3,4)
a =
1 0 0 0
0 1 0 0
0 0 1 0
linspace(1,3,10)
ans =
Columns 1 through 7
1.0000 1.2222 1.4444 1.6667 1.8889 2.1111 2.3333
Columns 8 through 10
2.5556 2.7778 3.0000
s String Variable
string
quotation '
Str1='Tom';
Str2='Pookie';
string
function
matrix element string
matrix column
row blank space string
Basic Operation 27
dot(A,B) dot product A B A B matrix dot product row
vector element column dot product column A
B
dot(A,B)
ans =
32
o Matrix
Matrix A B matrix column row
matrix row column A
[m x n] B [p x q] AB n = p matrix m x q
AB BA matrix MATLAB C = AB
C =A *B
p Matrix Scalar
matrix scalar element matrix A=[1 2];
C =2*A
C =
2 4
q - Matrix
matrix / //
element matrix
A=[1 2 3];
B=[4 5 6];
C=A-B
C =
-3 -3 -3
r Matrix
Matrix square matrix
28 Basic Operation
A2 = AA
MATLAB A2 A^2
A^2 A*A
A^3 A*A*A
s Matrix Polynomial
polynomial function x
f ( x ) = a n x n + a n 1 x n 1 +... a1 x + a 0
operation Matrix
MATLAB operation Matrix
operation elements
AA 1 = A 1 A = I
Basic Operation 29
inv(a) inverse matrix a a singular matrix matrix
inverse MATLAB
o Rank of Matrix
row matrix rank matrix
1 2 3
a=
2 4 6
p Determinant of Matrix
Determinant square matrix scalar matrix determinant
square matrix a MATLAB
det(a) determinant a
a=[1 2 3; 2 7 6; 5 4 8];
det(a)
ans =
-21
q Matrix
30 Basic Operation
matrix MATLAB function
linear equations
Ax = B
x= A B 1
MATLAB x=A\B
A\B = A-1B
xA = B
x = BA-1
MATLAB B/A
B/A = BA-1
/ MATLAB left matrix division
r Matrix Decomposition
matrix A matrix 2 matrix
Decomposition Factorization matrix matrix
decomposed matrix 3
1 0 0
L = 4 2 0
5 6 3
Basic Operation 31
Upper Triangular matrix, U matrix elements main diagonal
( main diagonal)
1 2 3
U = 0 4 5
0 0 6
A matrix
A = LU
MATLAB
UD =
-2.0000 -6.0000 1.0000
0 -1.0000 8.0000
0 0 2.5000
0 LU-decomposition
LU-decomposition permutes lower
triangular factor
32 Basic Operation
PA = LU
QQ T = I
Q 1 = Q T
MATLAB
[Q,R]= qr(A) matrix Q R A = QR Q orthonormal
R upper triangular matrix A Square
Matrix
A=[1 2 3; 5 8 7];
[Q,R]=qr(A)
Q =
-0.1961 -0.9806
-0.9806 0.1961
R =
-5.0990 -8.2369 -7.4524
0 -0.3922 -1.5689
0 decompose 3 A [m x n]
U, L R A
Q m x m
V n x n
S m x n
Basic Operation 33
A=[1 4;8 9];
[L,U]=lu(A)
L =
0.1250 1.0000
1.0000 0
U =
8.0000 9.0000
0 2.8750
[Q,R]=qr(A)
Q =
-0.1240 -0.9923
-0.9923 0.1240
R =
-8.0623 -9.4266
0 -2.8528
[Q,S,V] = svd(A)
Q =
0.2966 0.9550
0.9550 -0.2966
S =
12.5963 0
0 1.8259
V =
0.6301 -0.7765
0.7765 0.6301
s Array Operation
element matrix
element - by - element operation array operation
A = [1 2 3 4];
B = [2 4 4 5];
A * B matrix C c i = ai bi
array operation . *
C = A.*B
E = A.^B
34 Basic Operation
E element element A element B
A=[1 2 3 4 5];
B=[4 5 9 10 2];
A.*B
ans =
4 10 27 40 10
B.^A
ans =
4 25 729 10000 32
t
MATLAB
(1)
(2)
(2)
(3)
u Matrix
matrix
MATLAB function
rot90(A) matrix A 90
rot90(A,n) matrix A 90 n
fliplr(A) Matrix A column
flipud(A) Matrix A row
reshape(A,m,n) matrix A [m x n] element matrix A
mn MATLAB
column A
Basic Operation 35
diag(x) x matrix vector main diagonal x
element x vector matrix vector A diagonal
triu(A) square matrix matrix A main diagonal
A
triu(A,k) square matrix matrix A diagonal k
A
tril(A) square matrix matrix A main diagonal
A
tril(A,k) square matrix matrix A diagonal k
A
rot90(A)
ans =
3 4 8
2 2 6
1 0 3
tril(A)
ans =
1 0 0
0 2 0
3 6 8
triu(A,2)
ans =
0 0 3
0 0 0
0 0 0
diag(A)
ans =
1
2
8
flipud(A)
ans =
3 6 8
0 2 4
1 2 3
36 Basic Operation
2.4 Multidimensional Arrays
MATLAB 2 MATLAB
version 5 2 Matrix 2
x=[1 3 5; 4 2 8]
x =
1 3 5
4 2 8
y=[7 1 4;2 0 1]
y =
7 1 4
2 0 1
z=[4 2 1;3 6 9]
z =
4 2 1
3 6 9
3 3
3 x, y,
z
row column
(concatenates) cat
d=cat(3,x,y,z)
d(:,:,1)=
135
428
d(:,:,2)=
714
201
d(:,:,3)=
4 2 1
3 6 9
size(d)
ans =
2 3 3
x, y, z 2 x 3 d 2 x 3 x 3 cat
Cat(dims,A1,A2,A3,...)
Basic Operation 37
matrix A1, A2, A3,... matrix
dims matrix
Multi-dimensional Array
ndim(A) dimension A
B = permute(A,order) A B order
order vector B
element
ipermute(A,order) permute(A, order)
shiftdim(A,n) dimension A n
B = squeeze(A) dimension 1 B element
A 1
matrix vector
vector
g(:,:,1) =
1 4
7 2
38 Basic Operation
4 3
g(:,:,2) =
3 2
1 0
2 6
g(:,:,3) =
5 8
4 1
1 9
p=rand(2,1,4,3);
size(p)
ans =
2 1 4 3
p=squeeze(p);
size(p)
ans =
2 4 3
1-1-3 g
g(1,1,3)
ans =
5
n Cell Arrays
cell arrays { } 2
cell index
x(1,1)={[1 2;3 4]};
x(1,2)={5};
x(2,1)={linspace(0,10,10)};
x(2,2)={'Text Only'};
content addressing
x{1,1}=[1 2;3 4];
x{1,2}=5;
x{2,1}=linspace(0,10,10);
x{2,2}='Text Only';
matrix x 2 x 2 element cell x(1,1) matrix 2
x 2 x
Basic Operation 39
x
x =
[2x2 double] [ 5]
[1x10 double] 'Text Only'
size(x)
ans =
2 2
x
class(x)
ans =
cell
cell
x{1,2}
ans =
5
o Cell Array
40 Basic Operation
cell array matrix
x
x =
[2x2 double] [ 5]
[1x10 double] 'Text Only'
y
y =
[2x2 double] [2x2 double]
[2x3 char ] [1x2 double]
a=[x y]
a =
[2x2 double] [ 5] [2x2 double] [2x2 double]
[1x10 double] 'Text Only' [2x3 char ] [1x2 double]
b=[x;y]
b =
[2x2 double] [ 5]
[1x10 double] 'Text Only'
[2x2 double] [2x2 double]
[2x3 char ] [1x2 double]
reshape
c=reshape(b,2,4)
c =
[2x2 double] [2x2 double] [ 5] [2x2 double]
[1x10 double] [2x3 char ] 'Text Only' [1x2 double]
cell array
cell cell
cell matrix cell
matrix
deal
Basic Operation 41
c
c =
[2x2 double] [2x2 double] [ 5] [2x2 double]
[1x10 double] [2x3 char ] 'Text Only' [1x2 double]
c{1,4}
ans =
2 3
5 7
c{1,4}(2,1)
ans =
5
[p q] = deal(c{1,2:3})
p =
1 3
5 6
q =
5
class(x)
ans =
cell
size(x)
ans =
6 1
42 Basic Operation
2.6 Structures
3 MATLAB 5.x
structure MATLAB structure object (Data
Containers) fields (database)
structure
n Structure
MATLAB 5.x
field
field
part (name) (make)
(price) (remark) filed 4 field
field field
Parts.name ='Left motor';
Parts.make='GE';
Parts.price=3990;
Parts.remark='Re-build';
parts
parts =
name: 'Left motor'
make: 'GE'
price: 3990
remark: 'Re-build'
2
parts(2).name='Over head cam';
parts(2).make='ACME';
parts(2).price=420;
parts(2).remark='New';
parts
Basic Operation 43
parts =
1X2 struct array with fields:
name
make
price
remark
1 MATLAB
field
parts.name
ans =
Left motor
ans =
Over head cam
Parts(2).price
ans =
420
field
total = parts(1).price*35.4
total =
141246
o field
program
MATLAB 5.x
structure struct
parts=struct('name',N,'make',M,'price',P)
parts =
1x2 struct array with fields:
name
make
44 Basic Operation
price
matrix N, M ,P
field sub-field
parts.make.FirstChoice='GE';
parts.make.SecondChoice='PW';
parts
parts =
make:[1x1 struct]
getfield
F=getfield(S,'field')
F field F =
S S 1-by-1 structure.
F=getfield(S,{i,j},'field',{k})
F = S(i,j).field(k).
n Display Format
MATLAB
format short 4 22.1234
Basic Operation 45
format long 15 22.123456789012345
format + + , - +
format long
pi
ans =
3.14159265358979
format short e
pi
ans =
3.1416e+000
format long e
pi
ans =
3.141592653589793e+000
o
MATLAB echo
MATLAB
disp
A disp(A) A disp(Display)
MATLAB Display (string)
A=10;
disp(A) ; disp(newtons)
10
46 Basic Operation
newtons
fprintf output
disp fprintf output variable
(specifier) %e, %f %g
%e exponential notation 2.3456 + 2
%f
%g %e %f
specifier %6.2f 4 2
1
fprintf
A=10;
fprintf (Total force is %f newtons \n,A)
Total force is 10.000000 newtons
\n
fprintf (Total force is \n %f newtons \n,A)
Total force is
10.000000 newtons
MATLAB plot
plot
plot(x,y) Linear plot x y x y
semilogx(x,y) plot x y x log y
Basic Operation 47
Linear plot x1-y1 x2-y2 y
y1 y2 x
plot MATLAB graphic window
plot plot graphic window plot
figure Command Window File menu New Figure
graphic windows figure 1, figure 2, ..
n
plot ( plot
semilogx,... )
plot(x,y) Plot vector x vector y coordinate (xj , yj)
plot(y) Plot coordinate ( j, yj ) vector y
plot(z) complex number z = x + iy plot coordinate (Re(z), Im(z))
plot(A) A matrix plot coordinate (j,A1j), (j,A2j),.. j index
row plot A column index
plot(x,A) Plot matrix A m x n vector x x vector m
plot column A x vector x n
plot row A x
plot(A,x) plot vector x Matrix A A m x n vector x m
plot x column A vector x n plot x
row A
plot(A,B) plot column B column A A B m x n
plot curve n m coordinate
plot(x,y,str)
str character string
y = yellow . -
g = green * --
m = magenta X -. dash-dotted
48 Basic Operation
b = blue O : dotted
c = cyan +
w = white S
r = read D
k = black ^
V
>
<
P
H
MATLAB - ()
MATLAB y, g, m, ... plot string
r+ plot +
plot(x,y,str1,w,v,str2,...)
plot curve 1
plot(xi, yi) str1 plot (wi ,vi) str2
str MATLAB y, g, m ...
a = plot(x,y,str1,w,v,str2,...)
plot curve MATLAB a
plot (MATLAB
handle ) MATLAB
o Graphics Window
Graphics window
character string txt ='charactor string
'
Basic Operation 49
zlabel(txt) ( 3 ) z
text(x,y,txt) string txt plot coordinate (x,y)
Text vector string
vector x y txti (xi, yi)
text(x,y,txt,sc)
string txt plot coordinate (0,0)
(1,1) plot
legend(txt1,txt2,...)
legend curve plot txt1 curve
plot , txt2 curve plot
Legend(txt1,txt2,...,pos)
legend curve plot txt1 curve
plot , txt2 curve plot
pos pos
0 =
1 = ( MATLAB
)
2 =
3 =
4 =
-1 =
legend off legend plot
legend (M,txt1,txt2,...)
M handle legend M
M = plot(x,y,...) help legend
50 Basic Operation
plot MATLAB x, y
plot
axis
grid on
grid off
grid grid on grid off grid off grid on
q Graphic
graphic window
figure graphic window MATLAB
plot
clf graphic window
clc command window
Basic Operation 51
hold on graphics window plot plot
plot
hold off hold on
hold hold on hold off
ishold MATLAB hold plot hold 1
0
r Subplot
graphic window
MATLAB 1 Graphic window
sub - plot graphic window subplot
subplot(m,n,p)
sub-plot graphic window
matrix m x n plot sub-plot p
p 1 sub-plot
subplot subplot window subplot (1,1,1)
x=0:pi/100:2*pi;
y=sin(x);
z=cos(x);
plot(x,y,'+',x,z,'-')
52 Basic Operation
1
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
x=[10 12 14 16 18];
y=[1 2 3 4 5;1.2 2.3 3.4 4.5 5.6];
plot(x,y)
xlabel('This is X-axis title')
ylabel('This is Y-axis title')
title('This is Titel of the graph')
text(14,1.5,'This Text start at point (14,1.5)')
legend('First Graph','Second Graph',0)
Basic Operation 53
This is Titel of the graph
6
First Graph
5.5 Second Graph
4.5
This is Y-axis title
3.5
2.5
1
10 11 12 13 14 15 16 17 18
This is X-axis title
54 Basic Operation
This is Titel of the graph
40
30
20
This is Y-axis title
10
-10
-20
First Graph
Second Graph
-30
0 2 4 6 8 10 12 14
This is X-axis title
plot subplot
x=[10 12 14 16 18];
y=[1 2 3 4 5; 1.2 2.3 3.4 4.5 5.6];
subplot(2,2,1);
plot(x,y)
title('This is the graph at position 1 of 2x2')
subplot(2,2,2);
semilogx(x,y)
title('This is the graph at position 2 of 2x2')
grid on
subplot(2,2,3);
semilogy(x,y)
title('This is the graph at position 3 of 2x2')
subplot(2,2,4);
loglog(x,y)
title('This is the graph at position 4 of 2x2')
grid on
Figure Windows
MATLAB 5.3 MATLAB 6.0
graphic windows toolbars
sine MATLAB
X=linspace(0,4*pi);
Basic Operation 55
y=sin(x);
plot(x,y)
figure windows
Plot
Edit
Axes Properties Property Editor
56 Basic Operation
Graphic
M-file
"
Potential Flow
potential flow half-body (Uniform
flow Source) stream function
q
= Ur sin +
2
Basic Operation 57
U
q flow rate source source strength
plot = stream line plot
r = f()
q
2
r=
u sin
r=abs(r');zeta=zeta';
for m=1:10
x(:,m)=r(:,m).*cos(zeta);
y(:,m)=r(:,m).*sin(zeta);
end
hold on
plot(x,y);y=-y;plot(x,y);
title('Flow Over Half Body')
axis([-2 6 -1.5 1.5])
axis off;hold off
58 Basic Operation
Flow Over Half Body
x = Ae nt sin(d t + ) + A0 cos(t )
parameter
n =
k
m
natural frequency ,
=
c
damping ratio
2 km
d = n 1 2 damping frequency
Transient Vibration Steady State
Basic Operation 59
A0
f0 f0
A0 = =
(n2 ) + (2n )
2 2 2
n2 (1 r 2 ) 2 + (2r ) 2
Phase angle
2r
= tan 1
1 r2
Normalized magnitude AF0 k Phase angle, frequency ratio, r = damping
0 n
ratio
r=linspace(0,3,200);
r=r';
s=0.1;
x=1./sqrt((1-r.^2).^2+(2*s*r).^2);
phi=atan2(2*s*r,1-r.*r);
subplot(2,1,1)
a(1)=plot(r,x);
hold on
subplot(2,1,2)
b(1)=plot(r,phi);
hold on
s=0.25;
x=1./sqrt((1-r.^2).^2+(2*s*r).^2);
phi=atan2(2*s*r,1-r.*r);
subplot(2,1,1)
a(2)=plot(r,x,'b-.');
subplot(2,1,2)
b(2)=plot(r,phi,'b-.');
s=0.707;
x=1./sqrt((1-r.^2).^2+(2*s*r).^2);
phi=atan2(2*s*r,1-r.*r);
subplot(2,1,1)
a(3)=plot(r,x,'b:');
subplot(2,1,1)
b(3)=plot(r,phi,'b:');
s=1.0;
x=1./sqrt((1-r.^2).^2+(2*s*r).^2);
phi=atan2(2*s*r,1-r.*r);
subplot(2,1,1)
a(4)=plot(r,x,'b--');
xlabel('Frequency Ratio');
ylabel('Normalized Magnitude');
legend(a,'0.1','0.25','0.707','1.0')
subplot(2,1,2)
b(4)=plot(r,phi,'b--');
xlabel('Frequency Ratio');
ylabel('Phase Angle, Rad');
60 Basic Operation
legend(b,'0.1','0.25','0.707','1.0')
Normalized Magnitude
0.1
0.25
4 0.707
1.0
0
0 0.5 1 1.5 2 2.5 3
Frequency Ratio
4
0.1
Phase Angle, Rad
3 0.25
0.707
1.0
2
0
0 0.5 1 1.5 2 2.5 3
Frequency Ratio
Basic Operation 61
3 MATLAB FUNCTIONS
MATLAB MATLAB
function function
sub-directories file M-file M-file
function
function function parameter
( )
function(parameter1,parameter2,...)
sin(x) sine x
abs(x) absolute parameter x
3.1
MATLAB function
abs(x) absolute x
sqrt(x) 2 x
round(x) x x
fix(x) x x
floor(x) x x x - infinity
ceil(x) x x x + infinity
sign(x) x -1 x < 0, 1 x > 0 0 x = 0
rem(x,y) x y x/y
exp(x) ex
log(x) ln(x) natural logarithm x
log10(x) log10 x logarithm 10 x
62 MATLAB Function
3.2
MATLAB Radians
180 = rad
function MATLAB
1 1 1
sec( x ) = , cos ec( x ) = , cot( x ) =
cos( x ) sin( x ) tan( x )
1
arc sec( x) = arc cos x 1
x
1
arc cos( x) = arc sin x 1
x
x
arc cot( x) = arc cos
1+ x
2
MATLAB Function 63
tanh(x) hyperbolic tangent x sinh( x )
cosh( x )
asinh(x) inverse hyperbolic sine x ln x + x 2 + 1
acosh(x) inverse hyperbolic cosine x ln x + x 2 1
x 1
1+ x
atanh(x) inverse hyperbolic tangent x ln x 1
1 x
coth( x ) =
cosh( x )
sinh( x )
x 0, sech( x ) =
1
cosh( x )
x + 1
csch( x ) =
1
sinh( x )
, acoth( x ) = ln
x 1
x 1
1 1+ x 2 1+ 1 x2
acsch(x ) = ln +
x
,
asech( x ) = ln
0 x 1
x x
x y real i = 1
x real part z ; x = Re(z)
y imaginary part z ; y = Im (z)
MATLAB i j 1 i j
imaginary number function complex number MATLAB parameter z = x + iy
64 MATLAB Function
3.5 Polynomial Functions
polynomial
P ( x ) = a n x n + a n1 x n 1 +....+ a 2 x 2 + a1 x + a 0
P=[1, 2, 1] % f ( x) = x + 2 x + 1 2
Polyval(P,1)% f(1) 1
ans =
1
x=[1 2 3 4];
polyval(P,x)
ans =
4 9 16 25
n Polynomial
polynomial P(x) x P(x) = 0
order () polynomial complex
number MATLAB
polynomial roots
roots(A) polynomial A
x4 = 4 x4- 4 = 0
A=[1,0,0,0,-4];
B=roots(A)
B =
-1.4142
0.0000+ 1.4142i
MATLAB Function 65
0.0000- 1.4142i
1.4142
4 2 , 2i
D=[1,3,0,-1,0,2];
C=roots(D)
C =
-2.9098
-0.7186+ 0.6574i
-0.7186- 0.6574i
0.6735+ 0.5207i
0.6735- 0.5207I
o polynomial
MATLAB roots polynomial
poly
poly(A) polynomial vector A
B=[1,-3,-1,3];
A=roots(B)
A =
3.0000
1.0000
-1.0000
C=poly(A)
C =
1.0000 -3.0000 -1.0000 3.0000
C B
p polynomial
polynomial scalar polynomial scalar
P=[1, 2, 1] % P( x ) = x 2 + 2 x + 1
Q=2*P % Q( x) = 2( x 2 + 2 x + 1) = 2 x 2 + 4 x + 2
polyval(Q,1) % Q(1)
ans =
8
polynomial polynomial
MATLAB conv
conv(P,Q) polynomial
polynomial P Q
66 MATLAB Function
P=[1 2 1]; % P( x ) = x 2 + 2 x + 1
Q=2*P; % ( )
Q( x ) = 2 x 2 + 2 x + 1 = 2 x 2 + 4 x + 2
conv(P,Q) % P(x)*Q(x)
ans =
2 8 12 8 2
polynomial polynomial
MATLAB polynomial
decond
[A,B]=deconv(C,D) MATLAB polynomial C
polynomial D polynomial A
polynomial B
C=[3,4,-9,13,-1,1.5,-10.5,10,10];
D=[1,3,0,-1,0,2.5];
[A,B]=deconv(C,D)
A =
3 -5 6 -2
B =
0 0 0 0 0 0 0 -5 15
polynomial 3x 3
5x 2 + 6 x 2 polynomial 5x + 15
0 parameter function polynomial
vector parameter matrix MATLAB
row 1 row matrix row row parameter
MATLAB Function 67
max(A,B) MATLAB matrix A B
element (i, j) aij bij
68 MATLAB Function
[y,ind] = sort(x) y sort (x) ind index
element x
column vector x, row vector y, matrix A
x=[4;1;6]
x =
4
1
6
y=[1 8 9]
y =
1 8 9
min(A)
ans =
1 7 4
sort(x)
ans =
1
4
6
mean(A)
ans =
2.3333 9.3333 6.0000
sum(y)
ans =
18
cumsum(x)
ans =
4
5
11
cumprod(A)
ans =
1 9 8
2 108 32
8 756 192
o Logical Function
MATLAB Function 69
MATLAB function function
, element matrix element matrix function
B=[1 0 4;3 6 0;4 2 9]
B =
104
360
4 -2 9
any(B)
ans =
1 1 1
find(B)
ans =
1
2
3
5
6
7
9
all(B)
ans =
1 0 0
70 MATLAB Function
finite(B)
ans =
1 1 1
1 1 1
1 1 1
n file
MATLAB file fopen
fid=fopen(filename, permission)
file filename file
permission file directory
MATLAB MATLAB search path.
fid file identifiers file
MATLAB file
permission strings
'r' (read)
'w' file
'a' (append)
'r+'
'w+'
'a+'
MATLAB Function 71
file format binary code
file text 't' string
'rt' 'wt+' UNIX Macintosh text file
file fclose
st=fclose(fid) file file identifier, fid, fopen
st =0 file st = -1
st=fclose('all') file
o Binary File
binary file fread fwrite
[A,count]= fread(fid,size,precision)
binary data file fid
matrix A count
size
MATLAB file
N N element column vector
inf file ()
[M,N] matrix M x N column
count=fwrite(fid,a,precision)
72 MATLAB Function
element matrix A file fid
MATLAB column count
elements
precision
String
'char' - 8 bits
'uchar' unsigned character - 8 bits
'schar' signed character - 8 bits
'int8', 'int16','int32','int64' - 8,16,32 64 bits
'uint8', 'uint16', 'uint32', 'uint64' unsigned integer - 8,16,32 64 bits
'float32' floating point - 32 bits
'float64' floating point - 64 bits
computer
'short' - 16 bits.
'int' - 32 bits.
'long' - 32 64 bits.
'ushort' unsigned integer - 16 bits.
'uint' unsigned integer - 32 bits.
'ulong' unsigned integer - 32 bits or 64 bits.
'float' floating point - 32 bits
'double' floating point - 64 bits.
binary file
file
f1=fopen('c:\MATLABR11\work\myio1.dat','w');
A=linspace(0,2*pi,10);
st =fwrite(f1,A,'float32')
MATLAB Function 73
st =
10
file
f2=fopen('c:\MATLABR11\work\myio1.dat','r');
B=fread(f2,'float32');
fclose(f2);
file
f3=fopen('c:\MATLABR11\work\myio1.dat','r');
C=fread(f2,[2 5],'float32');
fclose(f3);
file
F4=fopen('c:\MATLABR11\work\myio1.dat','r');
D=fread(f2,[2,2],'float32');
E=fread(f2,[3,2],'float32');
fclose(f4);
B C D E
B =
0
0.6981
1.3963
2.0944
2.7925
3.4907
4.1888
4.8869
5.5851
6.2832
C =
0 1.3963 2.7925 4.1888 5.5851
0.6981 2.0944 3.4907 4.8869 6.2832
D =
0 1.3963
0.6981 2.0944
E =
2.7925 4.8869
3.4907 5.5851
4.1888 6.2832
74 MATLAB Function
binary file IEEE
MATLAB C FORTRAN
help fread
p Format File
text file file binary file
fscanf fprintf
[a,count]=fscanf(fid,format,size)
format file fid
format matrix a
count size
fread
format string %
d, i, o, u, x, e, f, g, s, c, [. . .] (scanset).
C %s character string,
%f floating point %d decimal point integer
MATLAB
count=fprintf(fid,format,a)
format data real part matrix a
format string file fid count
file
f2=fopen('c:\temp\iotest.txt','rt');
A=fscanf(f2,'%f %f',[2 5]);
B=fscanf(f2,'%f');
A
A =
0 1.1111 2.2222 3.3333 4.4444
0.5556 1.6667 2.7778 3.8889 5.0000
MATLAB Function 75
B
B =
1.0000
0.8496
0.4437
-0.0957
-0.6063
-0.9345
-0.9817
-0.7335
-0.2647
0.2837
"
Stress-Strain Curve
curve
stress-strain curve curve
stress strain
Youngs Modulus MPa
Ultimate Strength MPa
Percent Elongation at Fracture
76 MATLAB Function
file tensile.dat 2 column stress
strain column
kpsi
MPa 1 kpsi = 6.895 MPa
MATLAB
fopen
fid = fopen('c:\MATLABR11\work\tensile.dat','r');
A=fscanf(fid,'%f %f',[2 100]);
fclose(fid);
A=A';
100 file 2
stress strain 2 x 100 transpose
column
Stress = A(:,1)*6.895;
Strain = A(:,2);
Young = (Stress(3)-Stress(2))/(Strain(3)-Strain(2));
fprintf('Youngs Moduls = %7.3f MPa \n',Young)
Youngs Moduls = 172375.000 MPa
U_Strangth = max(Stress);
fprintf('Ultimate Tensile Stress = %7.3f MPa \n',U_Strangth)
Ultimate Teasel Stress = 524.020 MPa
plot(Strain,Stress,'^-');
xlabel('Strain')
ylabel('Stress')
title('Stress - Strain Curve')
MATLAB Function 77
500
400
S tres s
300
200
100
0
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
S train
78 MATLAB Function
4 M-FILE
4.1 M-File
MATLAB
C, FORTRAN, PASCAL,... MATLAB function
function
MATLAB Save extension " m "
MATLAB M-file M-file 2
script file
function function MATLAB
function M-file function file
M-file MATLAB plain text format program
Notepad save file save file extension m
MATLAB 5.x MATLAB Editor/Debugger
M-file file extension M-file
myfile.m command window MATLAB
myfile
M-file
MATLAB M-file directory path
MATLAB MATLAB directory sub-directory drive
MATLAB search path M-file
file path MATLAB
M-file directory M-file MATLAB
MATLAB search path directory MATLAB program
search path
M-Files 79
search path MATLAB
addpath directory search path directory
DOS
search path MATLAB 5.X click
File Set path... path
function file
script file
variable M-file
MATLAB input output
function file script file
parameter
80 M-Files
script file function file
function mypro(c)
Comment ( % )
comment
%
comment MATLAB
% help M-file
script file %
help file
function file % function
help
file
M-file
M-Files 81
script file
% Pythagoras Theorem for Me
a = input (Please input the first side);
b = input (Please input the second side);
c = sqrt (a^2 + b^2)
help pyta
Pythagoras' Theorem for Me
function file
function c = pyta (a, b)
% Pythagoras Theorem for Me
% format is c=pyta(a,b)
% where a and b are sides of the rectangle
% and c^2 =a^2+b^2
c = sqrt(a^2 + b^2)
Save file pyta.m
c = pyta(3, 4)
c =
5
Pyta (3,4)
ans =
5
x= Pyta (4, 3)
x =
5
help pyta
Pythagoras Theorem for Me
format is c=pyta(a,b)
where a and b are sides of the rectangle
and c^2 =a^2+b^2
M-file
82 M-Files
4.3 M-File
program computer MATLAB
program C, FORTRAN BASIC
MATLAB line number
subroutine function
MATLAB string, integer
precision
array dimension
function MATLAB
subroutine
MATLAB compile MATLAB
error
For loop Repetitive Control Structure
If - elseif - else - end Conditional Control Structure
While loop Repetitive Control Structure
n For Loop
For loop For loop ( Do loop)
for m = a: b
end
MATLAB (loop) m = a
end MATLAB
for m = a + 1
m = b a b
for m = a:b:c l a c b
M-Files 83
0 FORTRAN loop i j
integer FORTRAN MATLAB
MATLAB imaginary number 1
For Loop
for loop
for k = 1 : 5
for i = 1 : 5
p(k,i) = k * i ;
end
end
o If Statement
If
if
end
MATLAB MATLAB
end condition
84 M-Files
MATLAB
= ==
~=
MATLAB
> >
< <
=>
=<
AND &
OR |
if x == 0
a =5
end
x = 0 a = 5 x a = 5
If-Elseif-Else
else elseif
if 1
1
elseif 2
2
elseif 3
4
................
else n
n
End
1 MATLAB 1 end
MATLAB 2 MATLAB 2 end
MATLAB 3 MATLAB 3 end
M-Files 85
n MATLAB
end
p While - Loop
while loop for loop while loop
for loop loop
while-loop
while
end
loop MATLAB
end
a =0
while a < 5
a =a +1
b =5+a
end
0 loop
loop loop
Ctrl-C MATLAB
q Loop
program loop
Break
86 M-Files
MATLAB loop
end
for k = 1 : 5
y = k^2
if y = = 9
break
end
x = 5/(y-9)
end
MATLAB loop y y 9
MATLAB x y = 9 MATLAB
If (break) MATLAB
end loop for loop
control flow MATLAB 5.X switch - case
switch
case 1
1
case 2
2
case 3
3
...............
otherwise
n
end
switch MATLAB
M-Files 87
fprintf(' 4 \n')
otherwise
fprintf(' \n')
end
x x MATLAB x
x = 1 1
r
MATLAB
pause keyboard
pause(n) n
return M-file M-file
pause on off pause M-file
M-file
function MATLAB
88 M-Files
5 SOLUTION TO SYSTEM OF LINEAR EQUATIONS
5.1
n 1
nonlinear function function sin, log
n
............
a n1 x1 + a n 2 x2 + ... + a nn xn = bn
matrix
[ A]{ x} = {b}
[ A] 1[ A]{x} = [ A] 1 {b}
{ x} = [ A]1 {b}
5.2 Inverse
inverse
MATLAB
inverse Matrix MATLAB x
[ A]{ x} = {b}
x=inv(A)*b
x
2 x1 + x 2 = 1
x1 + 3x 2 + 5x 3 = 2
4 x1 6x 2 + 8x 3 = 4
MATLAB
A=[2,1,0;1,3,5;4,-6,8];
B=[1;2;4];
X=inv(A)*B
X =
0.4833
0.0333
0.2833
D=B-A*X
D =
1.0e-015 *
0.4441
0
x1 0.4441 x 10-15
inverse Matrix
analytical numerical
inverse Matrix MATLAB
matrix X = B/A X = A\B
5.3 Matrix
matrix MATLAB
MATLAB
Gaussian Elimination inverse matrix
inverse
matrix ill-condition matrix
singular matrix ( matrix determinant ) inverse
floating point Gaussian Elimination
Method ill-condition
[ A]{ x} = {b}
MATLAB matrix
x=A\b
A=[2,1,0;1,3,5;4,-6,8];
B=[1;2;4];
X=A\B
X =
0.4833
0.0333
0.2833
D=B-A*X
D =
0
A square matrix
x column vector
scalar
( A I ) x = { 0}
[ C]{ d } = { 0}
{ d } = { 0}
{d } {0} C inverse
A I = 0
QQ T = I Q T = Q 1
[B,C]=eig(A)
B =
-0.8069 -0.3437
0.5907 -0.9391
C =
-1.9282 0
0 11.9282
Principal Stress
Principal Stress Principal Direction stress
system
xx = 120, yy = 55, zz = 85, xy = 55, yz = 33, zx = 75 MPa
eigenvalue eigenvector
[Direc SP]=eig(s)
Direc =
-0.4654 -0.8372 0.2872
-0.8836 0.4587 -0.0944
0.0527 0.2977 0.9532
SP =
24.0644 0 0
0 176.7995 0
0 0 -110.8640
Mx + Kx = 0
d 2x
x column vector coordinate x = M mass matrix K
dt 2
stiffness matrix harmonic
x = Ae it
A x = 2 Ae it
[ K M ]x = 0
2
[ AM ]x = 0
m1 0 0 k1 + k 2 k2 0
M = 0 m2 0 K = k 2 k2 + k3 k 3
0 0 m3 0 k3 0
M=[1 1 1];
K=[10 10 10];
[A B]=threedof(M,K)
A =
0.5910 -0.7370 0.3280
-0.7370 -0.3280 0.5910
0.3280 0.5910 0.7370
B =
5.6982
3.9433
1.4073
-1
0 0.5 1 1.5 2 2.5 3
1
-1
0 0.5 1 1.5 2 2.5 3
1
0.5
0
0 0.5 1 1.5 2 2.5 3
eigenvalue
1. Interpolation MATLAB
Polynomial interpolation - 2
linear interpolation
Cubic-Spline interpolation - curve polynomial degree 3 2
slope
curve curve
n curve n-1 linear
interpolation curve cubic spline curve polynomial
degree 3
2. Curve fitting MATLAB Least-Square Curve Fitting curve
polynomial degree curve
6.2 Interpolation
n Linear Interpolation
linear interpolation
MATLAB interp1
0 interp1 x MATLAB x
() ()
0 0
1 200
2 600
3 680
4 800
x = [0 1 2 3 4]; % x
y = [0, 200, 600, 680, 800];
y1 = interp1(x, y, 2.5)
y1 =
640
t = 1.5 35 linear
interpolation ( x y )
s = [1.5 3.5];
y2 = interp1(x, y, s);
y2 =
400 740
o Cubic Interpolation
function cubic interpolation spline curve
interp1(x,y,s,cubic) x, y, s string cubic
MATLAB cubic interpolation
x = [0, 1, 2, 3, 4];
y = [0, 200, 600, 680, 800];
y1 = interp1(x, y, 2.5,'cubic')
y1 =
657.5000
1.5 3.5
s = [1.5 3.5];
y2 = interp1(x, y, s,'cubic')
y2 =
407.5000 735.0000
p Spline Interpolation
spline interpolation function
interp1(x,y,s,spline) x, y, s string spline
MATLAB cubic spline
interpolation
2.5 cubic spline
x = [0, 1, 2, 3, 4];
y = [0, 200, 600, 680, 800];
y1 = interp1(x, y, 2.5,'cubic')
y1 =
657.5000
s=[1.5 3.5];
y1 = interp1(x, y, s,'spline')
y1 =
421.2500 698.7500
spline
spline(x,y,s)
ans =
421.2500 698.7500
q Interpolation
y = x sin( x)
x y vector 1x 20 x
0 2 interpolation x
= 5 M-file
% Interpolation Demo
x=0:pi/5:2*pi;
y=x.*sin(x);
s=0:pi/30:2*pi; % Set interval for plot
% Linear
a=interp1(x,y,s);
a1=interp1(x,y,5);
% Cubic
b=interp1(x,y,s,'cubic');
b1=interp1(x,y,5,'cubic');
% Cubic Spline
c=interp1(x,y,s,'spline');
c1=interp1(x,y,5,'spline');
% Exact
d1=5*sin(5);
fprintf('Solution of x*sin(x) at x=5 by linear inter.= %f \n',a1)
fprintf('Solution of x*sin(x) at x=5 by cubic inter. = %f \n',b1)
fprintf('Solution of x*sin(x) at x=5 by spline inter. = %f \n',c1)
fprintf('Exact solution of function x*sin(x) at x=5 = %f \n',c1)
subplot(3,1,1)
plot(s,a,'-',x,y,'o')
text(5,2,'Linear Interpolation')
subplot(3,1,2)
plot(s,b,'-',x,y,'o')
text(5,2,'Cubic Interpolation')
subplot(3,1,3)
plot(s,c,'-',x,y,'o')
text(4,2,'Cubic Spline Interpolation')
Linear Interpolation
0
-5
0 1 2 3 4 5 6 7
5
Cubic Interpolation
0
-5
0 1 2 3 4 5 6 7
5
-5
0 1 2 3 4 5 6 7
function
interp2 2- interpolation
interp# interpolation # - MATLAB 6-
interpft Fast Fourier Transform Interpolation Method
griddata 2- interpolation
P ( x ) = a n x n + a n1 x n 1 +....+ a 2 x 2 + a1 x + a 0
ai
Least square curve fitting polynomial degree
ai
MATLAB
1.5 3.5
s=[1.5 3.5];
y1=polyval(p,s)
y1 =
412.0000 759.4286
5
Linear Least Square
0
-5
0 1 2 3 4 5 6 7
5
Second order
0
-5
0 1 2 3 4 5 6 7
5
Third order
0
-5
0 1 2 3 4 5 6 7
5
Fourth order
0
-5
0 1 2 3 4 5 6 7
interpolation
Least Square Fitting
"
Interpolation Curve Fitting
Impact of a Jet
(1 cos )
F = mU
m U
2 (flat plat) 90
(hemispherical cup) 180
F = mU
F = 2mU
1 2
600 g
F L = mgl
m g L
150 mm l
mgl
F=
L
% Initialized Data
LF=LF'; TF=TF'; VF=VF';LH=LH';TH=TH';VH=VH';
% List of Constant
grav = 9.81; % [m/s2]
NozzelDim = 10; % [mm]
High = 35 ; % [mm]
ArmLength = 150; % [mm]
mass = 0.6; % [kg]
% Initialize Figure and hold it
figure('NumberTitle','off','color',[1 1 1])
hold on
% Calculation and Plot for Hemispherical Cub
FlowRate = VH./TH ; % [Liter/s]
Flat Plate
Hemisphrical Cup
5
4
Force on V ane (N)
-1
0 0.5 1 1.5 2 2.5 3 3.5
Rate of Momentum Flow (N)
1) integrate
interpolation fitting integrate
2) function integrate analytical
integrate
numerical integration
integrate
integrate MATLAB 2
numerical integration function
MATLAB function
numerical integration Trapezoidal Numerical Integration
function integrate numerical
Simpson's Rule function file
y 50 x
y=x.*sin(x);
A=trapz(x,y)
A =
3.1406
= 3.14159 3
o Quadrature Integration
Quadrature numerical function MATLAB
function 2 function function function
function quad quadz function function file
function file function y = f(x) integrate quad quadz
integrate
quad(function,a,b)
quad(function,a,b,tol,trace)
quad(function,a,b,tol,trace,p1,p2...)
function function file (
function.m) a b integrate a b
tol, trace, p1. tol
relative error integrate MATLAB
0.001, trace function plot p1, p2 parameters
MATLAB help quad
MATLAB Simpson's Rule integrate
Quad8(function,a,b)
Quad8(function,a,b,tol,trace)
Quad8(function,a,b,tol,trace,p1,p2...)
Parameter function
quad
function quad M-file function file
save myint.m
function y = myint(x)
y = x.*sin(x);
A=quad('myint',0,pi)
A =
3.1416
= 3.14159 4
function quad8 function myint
format long
A=quad8('myint',0,pi)
A =
3.14159265358962
format long
pi
ans =
3.14159265358979
13
numerical
integration function trapz, quad quad8
trapz integrate
quad quad8 tol quad
quad8 0.001
integral x x 20
( script file)
x = 0:1/19:1;
for k = 1:20
A2(i) = quad(myint2,0,1,[],[],x(i));
end
dblquad(function,inmin,inmax,outmin,outmax,tol,trace,method)
integrate double integral function quad inmin, inmax
limit integrand outmin outmax limit
integrate function function file integrand
function option tol trace
function quad quad8 method option
integrate quad quad8 MATLAB
quad function file function(inner, outer) inner
outer integrate
function
dblquad('myint3',0,1,0,1)
ans =
0.5577
MATLAB integration
function MATLAB function function function
function function integrate
MATLAB Symbolic Integration Symbolic Toolbox
dy y ( x + x ) y ( x )
= y ( x ) = lim
dx x 0 x
y ( x k ) y ( x k 1 )
y ( x k ) =
x k x k 1
x = x k x k 1 function difference
x = [1, 2, 3, 4, 5];
y = [1, 1.3, 1.8, 2.1, 2.4];
dydx = diff(y)./diff(x)
dydx =
0.3000 0.5000 0.3000 0.3000
dy
dx
x=1 0.3000, dy
dx
x=2 0.5000, ...
"
indicated
power indicator
Indicated mean effective pressure, imep
W
imep =
V
Indicated Power
imepV N
Pi =
nr
- -
( CC ) ( bar ) ( bar )
141.0 16.0 15.0
164.25 47.0 11.0
186.50 42.0 9.5
207.55 37.0 8.0
230.00 33.0 7.0
324.13 21.0 4.5
410.40 14.5 3.0
500.00 11.0 2.0
590.04 8.5 1.5
680.00 7.0 1.0
770.00 5.0 1.5
815.00 4.5 1.5
860.00 3.5 3.5
numerical integration
function file
function [Power,imep]=ice_PV(V,PH,PL,N,nr)
plot(V,PH,V,PL)
ylabel('Pressure, bar');
xlabel('Volume, CC');
title('Indicator Diagram')
DP=PH-PL;
1200 rpm nr = 2 0
N=1200;
nr=2;
[Power imep]=ice_pv(V,PH,PL,N,nr);
In d i c a t o r D i a g r a m
50
45
40
35
30
P ress ure, bar
25
20
15
10
0
100 200 300 400 500 600 700 800 900
V o lu m e , C C
Ordinary Differential Equation (ODE) MATLAB
Partial Differential Equation (PDE) MATLAB toolbox
ODE first order order
MATLAB function initial value problem
function boundary value problems
dy
y = = g ( x, y )
dx
y = y ( x) y = g ( x, y )
y(x) 1 function
(initial condition) (boundary condition)
function general solutions y(x) boundary initial
ode23
[a b]=size(y);
y(a)
ans =
-3.1417
initial condition
y( x0 ) = a 0
y ( x 0 ) = a1
..........
y ( n 1) ( x 0 ) = a n 1
y ( n ) = g ( x, y, y ,... y ( n 1) )
v1 ( x) = y ( n 1)
v 2 ( x) = y ( n 2)
..........
v n 2 ( x) = y
v n 1 ( x) = y
vn = y
v1 ( x) = y ( n ) = g ( x, y, y ,... y ( n 1) )
v 2 ( x) = y ( n 1) = v1 ( x)
v 3 ( x) = y ( n 2) = v 2 ( x)
........
v n 2 ( x) = y = v n 3 ( x)
v n 1 ( x) = y = v n 2 ( x)
v n ( x)= y = v n 1 ( x)
First order n n
nonlinear second order ODE
y = g ( x, y, y ) = y (1 y 2 ) y 2
v1 ( x) = y v1 ( x) = y = y (1 y 2 ) y 2
v2 ( x) = y v2 ( x) = y = v1
v 2 = y,v1 = y v1
v1 = v1 (1 v 22 ) v 22
v 2 = v1
0 x 10 MATLAB command
t = [0 10];
initial = [0 0.25];
[x, y] = ode45(myode2,t,initial);
m = plot(x,y);
legend(m,'dy','y')
-1
-2
-3
-4
-5
-6
-7
-8
-9
0 1 2 3 4 5 6 7 8 9 10
x
y = x + 1 y y(1) = 2, y(3) = - 1
5
y x = 1 x = 3
R-K ODE
derivative
condition
R-K
shooting method
1 1
1 3-5
MATLAB
ODE order 2 ODE order 1
function dv = myode3(x,v)
dv=zeros(2,1);
dv(1)= x+v(2).*(1-x/5);
dv(2)= v(1);
1 3
ode45
[x,y]=ode45('myode3',intv,init);
[a b]=size(y);
y(a,:)
ans =
6.2568 6.2382
y(3)=6.2382 -1
slope -1 x = 1 y (1) = 1
slop y (1) = 4
init
init=[-4 2];
[x y]=ode45('myode3',intv,init);
[a b]=size(y);
y(a,:)
ans =
-0.6125 -2.4651
y(3) = - 2.4651 -1
y' -1 -4 interpolate
-1 linear
interpolation
4 ( 1)
1+ ( 1 6.2382) = 3.495
2.4651 6.2382
y (1) = 3.495
init=[-3.495 2];
[x y]=ode45('myode3',intv,init);
[a b]=size(y);
y(a,:)
ans =
0.5439 -1.0000
y(3) = 1
m=plot(x,y);
legend(m,'dy','y')
-1
-2
-3
-4
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
linear interpolation 3 3
Boundary Value Problems
ODE second order linear ODE
shooting method boundary value problem ODE linear
linear interpolation
G1 1
G2 2
R1 1 ( G1)
R2 2 ( G2)
D
3 G
o Nonlinear ODE
nonlinear ODE 3
x
y = x + 1
yy
5
y(1)=2 y(3) = -1
nonlinear yy
MATLAB
script file
function file myode4.m
function dv = myode4(x,v)
dv = zeros(2,1);
dv(1) = x+ v(1).*v(2).*(1-x/5);
dv(2) = v(1);
% First Try
G1 = -1; % 1
init=[G1 2];
[x,y]=ode45('myode4',intv,init);
[a b]=size(y);
while abs(y(a,2)-D)>1e-6 %
1E-6
G=G1+(G2-G1)*(D-R1)/(R2-R1); %
init=[G 2];
G1=G2; % 1
G2=G; %
[x,y]=ode45('myode4',intv,init);
[a b]=size(y);
R1=R2; % 1
R2=y(a,2); %
P=abs(y(a,2)-D); % loop
fprintf('Now your error is %10.6f \n',P)
end % loop plot
%
m=plot(x,y);
legend(m,'dy','y')
MATLAB error
10-6 MATLAB
0.5
-0.5
-1
-1.5
-2
-2.5
-3
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
"
(The Excact Solution of Boundary
Layer Theory)
(Boundary Layer)
2 f + ff = 0
= f ( )
u
U
u
U
f = df ()
d
U
= y
x
kinematic viscosity
x
y
potential flow viscous
flow Blasius Equation Boundary condition
F :
= 0 f = 0 = 0 f = 0
F :
, f = 1
infinity
infinity
f 1
% **************
G1=1;
init=[G1 0 0];
[x,y]=ode45('blas',intv,init);
[a,b]=size(y);
R1=y(a,2);
G2=2;
init=[G2 0 0];
[x,y]=ode45('blas',intv,init);
[a,b]=size(y);
R2=y(a,2);
% **************
while abs(y(a,2)-D)>1e-6
G=G1+(G2-G1)*(D-R1)/(R2-R1);
init=[G 0 0];
G1=G2;
G2=G;
[x,y]=ode45('blas',intv,init);
[a,b]=size(y);
R1=R2;
R2=y(a,2);
P=abs(y(a,2)-D);
fprintf('Now your error is %10.6f \n',P)
end
m=plot(x,y);
legend(m,'d2y','dy','y',0)
4.5
d2y
4 dy
y
3.5
2.5
1.5
0.5
0
0 1 2 3 4 5 6
99%
= y @ u = 0.99U
u
U
= f ( ) f = 0.99
interpolation run M-file shooting
shooting
Now your error is 0.514670
Now your error is 0.238315
Now your error is 0.033354
Now your error is 0.001918
Now your error is 0.000016
Now your error is 0.000000
ODE MATLAB
a=y(:,2);
b=interp1(a,x,0.991,'spline')
b =
4.9654
Reynolds Number, Re x = Ux
=
Ux
4.965x
=
Re x
2 plot MATLAB
plot plot x, y 2
9.1 plot 2
plot x, y plot
n Error Bar
error bar
errorbar(x,y,e,str)
plot(x,y) error bar e
coordinate plot x-y str option
character string x,y
errorbar(x,y,l,u) error bar (xi , yi ) yi
li yi ui
x = linspace (0,15,40);
y = exp(cos(x)) ;
delta = 0.1*y ;
errorbar (x,y, delta)
2.5
1.5
0.5
0
-2 0 2 4 6 8 10 12 14 16
o Graph Function
function file plot function Function
MATLAB fplot
fplot (function, lim, str, tot)
plot function function ( function file function.m)
lim vector Limit function plot
2 lim = [xmin xmax] minimum
maximum x lim = [xmin xmax ymin ymax]
option str
tot relative error tot
lim = [1 0];
fplot(exp(x),lim)
1.5
0.5
0
1 2 3 4 5 6 7 8 9 10
p Polar Plot
plot polar coordinate polar
theta = linspace(0,2*pi,200);
r = sqrt(abs(sin(theta)).*abs(cos(theta)));
polar(theta,r)
option string ,
plot
90
0.8
120 60
0.6
150 0.4 30
0.2
180 0
210 330
240 300
270
subplot(2,2,1)
quiver(real(z),imag(z))
title('quiver')
subplot(2,2,2)
feather(real(z),imag(z))
title('feather')
subplot(2,2,3)
compass(real(z),imag(z))
title('compass')
x=[1 2 1 3 4 5 3 2 3 4 4 1 6 7];
plot
quiver feather
4 4
3 2
2 0
1 -2
0 -4
1 2 3 4 0 5 10 15
compass rose
90 5 90 4
120 60 120 60
2.5 2
150 30 150 30
180 0 180 0
bar graph
bar(x) bar graph x
bar(x,z) bar graph x vector z
stairs(x) stairs graph x (stairs graph bar graph )
stairs(x,z) stairs graph x vector z
x
subplot(2,2,1)
hist(x)
title('Histogram')
subplot(2,2,2)
bar(x)
title('Bar Graph')
subplot(2,2,3)
stem(x)
title('Stem Graph')
subplot(2,2,4)
stairs(x)
title('Stairs Graph')
3
4
2
2
1
0 0
0 2 4 6 0 5 10 15 20
5
4
4
3
2
2
0 1
0 5 10 15 20 0 5 10 15 20
comet(x,y) vector x y
pie(x) vector x
element
element vector x
pie(x,y) vector x
element x vector y x
0 1 element y 1 element
x
pie(x,condition) condition
16%
26%
18%
9.2 3
MATLAB 3
MATLAB 3
(mesh) 3
plot 3 MATLAB
n Plot 3
plot coordinate (x,y,z) Cartesian Coordinate
plot3
plot
plot3(x,y,z)
xlabel('X')
ylabel('Y')
zlabel('Z')
title(' 3-D Plot')
3-D Plot
0.5
0
Z
-0.5
8
6 8
4 6
4
2
2
Y 0 0
X
o 3
3
z = f (x,y)
zij = f(xi,yj)
x vector m y vector n
plot m x n plot3 m n plot m
zij = f (xij,yij)
p
mesh, meshc, meshz waterfall
mesh function
x y 0 2
script file
x = linspace(0,2*pi,40); % x vector 1 x 100
y = x; % y vector 1 x 100
z = sin(x)*cos(y); % z [100 x 1] x [1 x 100] = [100 x 1]
subplot(2, 2, 1);
mesh(x, y, z);
title('Mesh Plot')
subplot(2, 2, 2);
meshc(x, y, z) ;
title('Meshc Plot')
subplot(2, 2, 4)
waterfall(x, y, z)
title('Waterfall')
q
mesh
MATLAB
mesh
3 surf mesh
MATLAB shading 3
surf
x = linspace(0,2*pi,40); y = x; z = sin(x)'*cos(y);
subplot(2,1,1);
surf(x,y,z);shading interp
axis off
title('Surface Plot')
subplot(2,1,2)
[u v]=meshgrid(x,y);
surfnorm(u,v,z);shading flat
axis off
r
3
view
40
-0.2
-0.4 0.4
35 0.8
-0.2
30 -0.8 -0.8
-0.4
0.6 0 -0.6
25 -0.6 0
0.2
20 -0.2 0
0.2
-0.4 0.4
0.6 0.6
15 0
-0.6
10 -0.8
0.8 0.4 0.2
5
5 10 15 20 25 30 35 40
bar3(...,'grouped')
bar3(...,'stacked')
bar3(...,linespec) string
3
x = 3 2 5 7 9 6 4 8 4 10]';
y = 2*x-3;
z = y*x';
bar3(z)
stem
x=[3 2 5 7 9 6 4 8 4 10]';
y=2*x-3;
z=y*x';
stem3(x,y,z)
xlabel('This is x')
ylabel('This is y')
zlabel('This is z')
150
This is z
100
50
0
20
15 10
10 8
6
5
4
This is y 0 2
This is x
9.3
MATLAB function
MATLAB
3 -- Red-Green-Blue (RGB) Color RGB color (0, 0, 0)
RGB color (1 , 1, 1) RGB
RGB
0 1
MATLAB (color map)
plot color map matrix m x 3 row 3 RGB color
matrix m
MATLAB color map MATLAB
MATLAB m color map
shading shading interp
colormap ( map)
9.4
MATLAB function
MATLAB function frame
movie
movie frame frame figure window
plot frame
frame
M(n,j) = getframe frame j figure window
frame
movie(M) M 1
movie(M,n) M n
movie(M,n,FPS) M n FPS frame
FPS MATLAB 12 frame
MATLAB
FPS
n = 20;
format format
MATLAB plot
plot
fixed a
= axis [xmin,xmax,...] plot axis(a), axis(axis)
plot axis a
frame
frame
Windows multi-tasking
cpu
MATLAB
frame-per-second
"
n Flow Pass Rotating Cylinder
2 stream line
stream function contour line
stream line stream function
potential flow doublet
vortex
stream function
a, K U
M-file a =2 2aU
=K
circulation 4 K= 0
K
M-file
K=0;
phi=sin(zeta)*(r./a - a./r)-K*log(r/a);
[x y]=pol2cart(zeta,r);
co= [-150 -100 -75 -50 -25 -10 -1 -0.1 0.1 1 10 25 50 75 100 150];
subplot(2,2,1)
contour(x,y,phi,co,'b'); %
axis equal
axis off
axis([-6 6 6 6])
K=100;
phi=sin(zeta)*(r./a a./r)-K*log(r/a);
[x y]=pol2cart(zeta,r);
co=[-150 100 75 50 25 10 1 0.1 0.1 1 10 25 50 75 100 150];
subplot(2,2,2)
contour(x,y,phi,co,'b');
axis equal
axis off
axis([-6 6 -6 6])
K=200;
phi=sin(zeta)*(r./a - a./r)-K*log(r/a);
[x y]=pol2cart(zeta,r);
co= [-300 -250 -150 -100 -75 -50 -25 -10 -1 -0.1,...
0.1 1 10 25 50 75 100 150];
subplot(2,2,3)
contour(x,y,phi,co,'b');
axis equal
axis off
axis([-6 6 -6 6])
K=300;
phi=sin(zeta)*(r./a - a./r)-K*log(r/a);
[x y]=pol2cart(zeta,r);
co= [-400 -300 -250 -200 -150 -100 -80 -75 -65 -60,...
-40 -30 -1 5 10 25 35 50 60 75];
q 2ay
= Uy tan 1 2
2 x + y2 a 2
potential flow Vx =
y
Vy =
x
gradient stream function
stream line velocity vector
contour plot stream lines
x y gradient
velocity vector quiver
M-file
% Stream Line Plot With Velocity Vector
a=2;
Response Surface
single DOF damped forced vibration
2 function frequency ratio damping ratio
damping ratio
MATLAB
MATLAB toolbox Symbolic Mathematics
Symbolic Math Toolbox
MATLAB Toolbox Student Edition MATLAB MATLAB 5.x
version
MATLAB 5.x Symbolic
Toolbox MATLAB 5.x
Symbolic Mathematics
sin(x) x
sin(x) symbolic mathematic x
function sin(x) sin(x) d sin( dx
x)
=
cos(x)
Symbolic Math Toolbox symbolic function MATLAB
Maple V. Software Package software symbolic mathematic
University of Waterloo Watterloo Maple
Software, Inc. Canada
variable
symbolic variable / symbolic expression MATLAB
symbolic variable sym
x=sym(x)
x symbolic variable x
x symbolic expression
f=x^2+3*x-5;
g=2*x^2-5*x+2;
f g symbolic expression
syms symbolic variable
syms ex1 ex2... symbolic variable expressions expression
x, y z symbolic variable
syms 'x' 'y' 'z'
s=sym('exp(bc)*sin(z)');
findsym(s)
ans =
bc, z
number MATLAB
sparse 2-D real (or complex) sparse matrix
x=sym('x');
class(x)
ans =
sym
f=5*x^2-3*x-1;
class(f)
ans =
sym
p Expression
expression function function
collect(s) expression S
collect(s,v) collect(s) v independer variable
expand(s) expression s
factor(s) expression s
simple(s) s
simplify(s) s Maple
function expression
x=sym(x)
s1= x^2-4*x+4;
s2=(x*cos(x))^2-x^2;
s3=(x-3)*(x-6)*(x+2)/(x^2-4*x-6);
factor(s1)
ans =
(x-2)^2
expand(s2)
ans =
x^2*cos(x)^2-x^2
factor(s2)
ans =
x^2*(cos(x)-1)*(cos(x)+1)
collect(s3)
ans =
(x-3)*(x-6)*(x+2)/(x^2-4*x-6)
expand(s3)
ans =
1/(x^2-4*x-6)*x^3-7/(x^2-4*x-6)*x^2+36/(x^2-4*x-6)
x = sym(x)
s1= x^2-4*x+4');
s2= (x*cos(x))^2-x^2
s3= (x-3)*(x-6)*(x+2)/(x^2-4*x-6)
[s4 s5]=numden(s3)
s4 =
(x-3)*(x-6)*(x+2)
s5 =
x^2-4*x-6
sym2poly(s4)
ans =
1 0 0 36
s4 + s5
factor(ans)
ans =
x^3-6*x^2+30-4*x
solve(s)
syms x1 y1 z1
s1= x1+y1+z1-5;
s2= 2*x1-y1+2*z1-4;
s3= x1-4*y1-z1+2;
a=solve(s1)
a =
-y1-z1+5
[x y z]=solve(s1,s2,s3)
x =
9/2
y =
2
z =
-3/2
double(x) x expression
double precession number
x
double(x)
ans =
4.5000
symbolic MATLAB
analytical solution MATLAB numerical solution
S1=sym('x^3*exp(x)*sin(x))=2');
[b]=solve(s1)
b =
.2539413645466444913948333 1.040276743255826267579410*i
o Solution to ODE
first-order-ODE
dy
y' = = g( x, y)
dx
first order 1
dsolve('Dx = -a*x^2')
ans =
1/(a*t+C1)
first order
dsolve(equation1, equation2,...,condition)
dsolve(equation1, equation2,...,condition)
2 output S MATLAB
field S.f S.g (
MATLAB 5 12)
field
S.f
ans =
exp(t)*cos(t)+2*exp(t)*sin(t)
S.g
ans =
-exp(t)*sin(t)+2*exp(t)*cos(t)
first order 3
[u1 v1 w1] = dsolve('Du=v, Dv=w, Dw=-u','u(0)=0, v(0)=0, w(0)=1')
u1 =
1/3*3^(1/2)*exp(1/2*t)*sin(1/2*t*3^(1/2))-
1/3*exp(1/2*t)*cos(1/2*t*3^(1/2))+1/3*exp(-t)
order
nonlinear second order ODE
d2y dy
2
= y 5
dx dx
y(0) = 0.25
dsolve('D2y=y-Dy-5','Dy(0)=0,y(0)=0.25')
ans =
5+(-19/8-19/40*5^(1/2))*exp(1/2*(5^(1/2)-1)*t)-19/40*(5^(1/2)-
1)*5^(1/2)*exp(-1/2*(5^(1/2)+1)*t)
function integrate
integrate symbolic MATLAB
numerical integration
diff(s1)
ans =
3*x^2*exp(x)*sin(x)+x^3*exp(x)*sin(x)+x^3*exp(x)*cos(x)
diff(s1,'x')
ans =
3*x^2*exp(x)*sin(x)+x^3*exp(x)*sin(x)+x^3*exp(x)*cos(x)
diff(s1)
ans =
3*x^2*exp(x)*sin(x)+x^3*exp(x)*sin(x)+x^3*exp(x)*cos(x)
diff(s1,'t')
ans =
0
diff(s2)
ans =
3*x^2+6*x+5
diff(s3,3)
ans =
-3*sin(x)-x*cos(x)
integrate
int('x^4')
ans =
1/5*x^5
int('x*cos(x)')
ans =
cos(x)+x*sin(x)
int('x*sin(x)',0,pi)
ans =
pi
int('x^2/sin(x)')
ans =
int(x^2/sin(x),x)
MATLAB integrate
n Laplace Transform
Laplace Transform function f(t) time domain function L(s) s-domain
transformation
f (t )e
st
L ( s) = dt
0
L = laplace(F,var1,var2)
Laplace transform symbolic expression F var1-
domain function var2-domain
L(var2) transform F(var1) option var1,
var2 MATLAB var1 t var2 s
F, var1 var2 sym
sym
f = ilaplace(L,var1,var2)
inverse Laplace transform symbolic expression L
L option var1 var2 t s
f(var2) inverse transform L(var1) F,
Laplace transform
f (t ) = 5e 2 at cos t
MATLAB
syms a s t w
f=5*exp(-2*a*t)*cos(w*t);
L=laplace(f,t,s)
L =
5*(s+2*a)/((s+2*a)^2+w^2)
ilaplace(L,s,t)
ans =
5*exp(-2*a*t)*cos(w*t)
o Fourier Transform
function function
function time-domain frequency-domain
Fourier Transform
F ( ) = f ( t )e
jt
dt
f (t) = F ( ) e
jt
dt
syms x t
fourier(exp(-x^2),x,t)
ans =
pi^(1/2)*exp(-1/4*t^2)
f=ifourier(F,t,x)
f =
1/2*4^(1/2)*exp(-x^2)
simple(f)
ans =
exp(-x^2)
K ( t a) dt = K
for t = a
p Z-Transform
transform transform function
discrete-time domain Z-transform
F ( z) = f ( n) z
n=0
n
syms k n w z
ztrans(2^n)
ans =
z/(z-2)
iztrans(ans)
ans =
2^n
F=ztrans(cos(n*k),k,z)
F =
z*(-cos(n)+z)/(-2*z*cos(n)+z^2+1)
F=ztrans(cos(n*k),n,w)
F =
w*(-cos(k)+w)/(-2*w*cos(k)+w^2+1)
f=iztrans(exp(x/z),z,k)
f =
x^k/k!
F=ztrans(f,k,z)
F =
exp(x/z)
o 2
1 f(x)
f(x)
df/dx f(x)
int f f(x)
simple f f(x) ()
f(x) f(x)
num f
f(x) f(x)
den f
1/f f(x) 1/f(x)
finv f(x) inverse function
f +a f(x) f(x) + a
f -a f(x) f(x) - a
f *a f(x) f(x) * a
f / a f(x) f(x) / a
f^a f(x) f(x) ^ a
f(x+a) f(x) f(x + a)
f(x*a) f(x) f(x * a)
f +g f(x) f(x) + g(x)
f g f(x) f(x) - g(x)
f *g f(x) f(x) * g(x)
f /g f(x) f(x) / g(x)
f(g) f(x) f(g(x))
g =f g(x) f(x)
swap f(x) g(x)
4 Function Calculator
function f(x) list funtool
f(x) function file fxlist
fxlist function function
Insert f(x) list
Cycle f(x) f(x) list
Delete function f(x) list ( list)
funtool
funtool function
MATLAB Graphics User Interface (GUI)
mouse MATLAB
Calculus.
diff Differentiate.
int Integrate.
limit Limit.
taylor Taylor series.
jacobian Jacobian matrix.
symsum Summation of series.
Linear Algebra.
diag Create or extract diagonals.
triu Upper triangle.
tril Lower triangle.
inv Matrix inverse.
det Determinant.
rank Rank.
rref Reduced row echelon form.
null Basis for null space.
colspace Basis for column space.
eig Eigenvalues and eigenvectors.
svd Singular values and singular vectors.
jordan Jordan canonical (normal) form.
poly Characteristic polynomial.
expm Matrix exponential.
Simplification.
Solution of Equations.
solve Symbolic solution of algebraic equations.
dsolve Symbolic solution of differential equations.
finverse Functional inverse.
compose Functional composition.
Integral Transforms.
fourier Fourier transform.
laplace Laplace transform.
ztrans Z transform.
ifourier Inverse Fourier transform.
ilaplace Inverse Laplace transform.
iztrans Inverse Z transform.
Conversions.
double Convert symbolic matrix to double.
poly2sym Coefficient vector to symbolic polynomial.
sym2poly Symbolic polynomial to coefficient vector.
char Convert sym object to string.
Basic Operations.
Special Functions.
sinint Sine integral.
cosint Cosine integral.
zeta Riemann zeta function.
lambertw Lambert W function.
Demonstrations.
symintro Introduction to the Symbolic Toolbox.
symcalcdemo Calculus demonstration.
symlindemo Demonstrate symbolic linear algebra.
symvpademo Demonstrate variable precision arithmetic
symrotdemo Study plane rotations.
symeqndemo Demonstrate symbolic equation solving.
11.1 M-book
word processing
word processing
copy
word
processing
word processing
word processing
M-book
M-book 2 Microsoft Word for Window
program word processing program word processing
MATLAB
Word Word
MATLAB background
Word MATLAB
program M-book Save file Word document file (.doc)
180 M-book
Word 97 Math Works MATLAB
5.0 download file Internet
www.mathworks.com MATLAB 5.1 Word 97
Word MATLAB
MATLAB MATLAB directory Word
template
M-book template Word Word
template Word template
Normal.dot MATLAB Word template M-book.dot
template Word MATLAB macro
11.2
Word MATLAB M-book Word
Word template Normal.dot document file M-
book
file Word
MATLAB ()
Dynamics Data Exchange (DDE) Word MATLAB
macros - DDE Cells
MATLAB Word
styles text cells
menu Notebook Menu bar Word
M-book 181
Word template M-book.dot
document file M-book document
document template M-book New M-book document
file Insert Menu insert file dialog box
file M-book
n Input cell
Input cell cell text cell text
input cell
input cell
182 M-book
style M-book input cell
Courier New 10 points
input cell
normal text
A=10;
B=20;
C=A*B
o input cell
input cell cell MATLAB cell
MATLAB cell
input cell
input cell input cell
p AutoInit Cell
M-book 183
input cell file
(Automatic Initialize) AutoInit Cell AutoInit Cell
input cell
input MATLAB
Highlight
Notebook menu Define AutoInit Cell ( short cut key)
M-book AutoInit Cell Cell mark
Courier New 10 points
q MATLAB
input cell MATLAB input cell
AutoInit Cell M-book
input cell M-book MATLAB
input cell cursor cell Notebook
Menu Evaluate Cell Ctrl-Enter
input cell M-book Notebook Menu Evaluate M-book
Alt-R Notebook M-book
input cell M-book highlight input cell ( text
text MATLAB) Notebook
Menu Evaluate cell Ctrl-Enter M-book input cell
cell
r
Notebook output cell output cell ,
Command Window MATLAB Output cell
M-book input cell output text input cell output cell
input cell text input cell
Output cell Command Windows
, Echo,
input cell output cell
184 M-book
output cell Notebook output cell
input cell output cell Notebook output
cell output cell
input cell input cell output 1 Notebook
output cell output output
input cell
output Courier New 10 points
Notebook Menu option
input cell output cell text highlight cell
Notebook Menu Undefined cell Alt-U
output cell Highlight output cell Notebook Menu Purge
Output Cell Alt-P
M-book 185
MATLAB error input cell cell
error MATLAB input cell input cell
t Graphic Output
Graphic output output cell
Graphic window M-book Notebook Menu option
Options window cheek box Embed Figures in M-book box
output cell M-book graphic
window command window
Toggle Graph Output for Cell Notebook Menu
Graphic Output cell M-book
Output cell ( Embed Figures in M-book)
input cell cursor cell Toggle Graph output
for cell Notebook Menu cell mark
Word
Graphic Output
Option Notebook Menu
Mouse click picture holder
mouse
MATLAB M-book
click picture holder
shift drag holder
holder
16 256
option Notebook Menu
u Calculate Zone
calculate zone calc zone text, input cell, output cell
M-book calc zone M-book calc zone section
brake brake section calc zone
input output M-book calc zone highlight
186 M-book
, input, output zone Notebook Menu
Define calc zone MATLAB section calc zone input cell
input cell zone Evaluate calc zone
Notebook Menu
calc zone calc zone
zone M-book
M-book 187
Short cut Key
12 Evaluate M-book Alt - R M-book input cell
13 Evaluate loop Alt - L M-book loop Cell
Cell
loop
14 Bring MATLAB to Alt - M MATLAB window foreground MATLAB
Front command window background
15 Notebook Options.. - option
1. Number format
format MATLAB
2.
2.1 M-bookEmbed Figures in M-
book
2.2 2.1 16 256
3. M-book Input cell
Stop Evaluation on Error
Style Font
Normal Times New Roman 10 points
AutoInit Courier New 10 points
Error Courier New 10 points
Input Courier New 10 points
Output Courier New 10 points
word Thai
Edition style
1. Format Menu Style
188 M-book
2. Style Window
3. window (style)
4. style highlight style
5. Click Modify Menu bar
6. Fonts...
7. Fonts window ,
8. Click OK Fonts style window
9. style
10. click Apply
Word
M-book 189
12 Handle Graphic
MATLAB
(Low Level Command)
(Graphical User Interface,
GUI) MATLAB
MATLAB
MATLAB
MATLAB
Figure window MATLAB Axes
Figure window axes
Parent & Child Object Hierarchy object
MATLAB
Handle Handle
Handle
Handle
handle
Object
Root object Root object MATLAB
Figure object MATLAB
Axes object
Image object
Light object. Patches Surfaces
Line object
patch object
Rectangle
Surface object
text object
uicontextmenu object Context menu
uicontrol object MATLAB GUI
uimenu object Menu bar Figure window.
object MATLAB
Root
Figure
MATLAB
Handle MATLAB Handle
(Property)
MATLAB (Default Value)
Error
GUI GUI environment
High-Level Low-Level
MATLAB High-level graphics routines plot surf
Low-level graphics routines
High-level graphics routines
High-level routines
high-level graphics routines
High-level graphics routines
Low-level graphics routines
high-level graphics routines plot MATLAB
MATLAB axes
x Xdata x y z
axes MATLAB axes
figure window axes MATLAB figure window
MATLAB
high-level functions plot plot graphics objects
axes ( Position Units)
low-level line
high-level functions
hold NextPlot
BusyAction MATLAB callback (
object )
HandleVisibility handle
Interruptible
Parent Parent
Selected
SelectionHighlight
Tag
Type object figure, line, text
UserData
Visible
MATLAB
LineStyle XMinorTickMode
MATLAB
2 3
M-files
MATLAB version
2 3
GET
Graphic object
get(object_handle)
returned_value = get(object_handle,'PropertyName');
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
handle
handle
fig_handle = gcf
fig_handle =
1
axes_handle = gca
axes_handle =
73.0007
get(fig_handle)
BackingStore = on
CloseRequestFcn = closereq
Color = [0.8 0.8 0.8]
Colormap = [(64 by 3) double array]
CurrentAxes = [73.0007]
CurrentCharacter =
WindowButtonUpFcn =
WindowStyle = normal
ButtonDownFcn =
Children = [73.0007]
Tag =
Type = figure
UIContextMenu = []
UserData = []
Visible = on
get(line_handle)
Color = [0 0 1]
EraseMode = normal
LineStyle = -
LineWidth = [0.5]
Marker = none
MarkerSize = [6]
MarkerEdgeColor = auto
MarkerFaceColor = none
XData = [ (1 by 200) double array]
YData = [ (1 by 200) double array]
ZData = []
ButtonDownFcn =
Children = []
Clipping = on
20 Handle Graphic
0
CreateFcn =
DeleteFcn =
BusyAction = queue
HandleVisibility = on
HitTest = on
Interruptible = on
Parent = [73.0007]
Selected = off
SelectionHighlight = on
Tag =
Type = line
UIContextMenu = []
UserData = []
Visible = on
get
l_color=get(line_handle,'Color')
l_color =
0 0 1
l_color
[0 0 1] RGB
Structure
output get MATLAB
structure array field field field
a = get(line_handle);
cell array
get(gca,camera_props)
ans =
'auto' 'auto' 'auto' 'auto'
9 set
set
set
set(object_handle,'PropertyName','NewPropertyValue')
object_handle handle
PropertyName
NewPropertyValue
NewPropertyValue
20 Handle Graphic
2
RGB
[1 0 0]
set(line_handle,'Color',[1 0 0])
quote string
MATLAB
set
set(object_handle,'PropertyName')
MATLAB
MATLAB
set(line_handle,'LineStyle')
[ {-} | -- | : | -. | none ]
[ {-} | -- | : | -. | none ] { }
set(line_handle,'LineWidth')
A line's "LineWidth" property does not have a fixed set of property values.
Set(object_handle)
set(axes_handle)
AmbientLightColor
Box: [ on | {off} ]
set
structure arrays cell arrays
view1.CameraViewAngleMode = 'manual';
view1.DataAspectRatio = [1 1 1];
view1.ProjectionType = 'Perspective';
set(gca,view1)
field a field
a.GridLineStyle
ans =
'-'
'--'
':'
'-.'
'none'
case sensitive
structure field case sensitive
20 Handle Graphic
4
a.gridlinestyle
??? Reference to non-existent field 'gridlinestyle'.
MATLAB
MATLAB MATLAB
get factory-defined
a = get(0,'Factory');
SelectionHighlight uimenu on
Get(0,'FactoryObjectTypePropertyName')
get(0,'FactoryTextFontName')
Windows
ans =
Helvetica
Helvetica
findobj
h = findobj
findobj handles
h = findobj
handle PropertyName
PropertyValue
findobj handle
h = findobj(objhandles,...)
handles
h = findobj(objhandles,'flat','PropertyName',PropertyValue,...)
findobj('Color','r')
20 Handle Graphic
6
Color property red r [1 0 0]
MATLAB findobj
handle
copyobj
new_handle = copyobj(h, p)
copyobj
Parent handle parent
line
axes
new_handle = copyobj(h, p)
handle h handle
children handle p h p
new_handle
new_handle(i) h(i) ] parent
p(i) h p h parents
p new_handle(i) h parent p(i) length(new_handle)
length(p).
h p new_handle(i) h(i)
Parent p new_handle length(h)
surface figure
surface
h = surf(peaks);
colormap hot
surface colormap figure view grid
axes surface
gca
handle axes ( gca = Get Current Axes)
h = gca
get(gcf,'CurrentAxes')
MATLAB
current axes MATLAB
plot, text, surf
current axes current figure current axes
gcbo
handle callback
h = gcbo
[h, figure] = gcbo
20 Handle Graphic
8
CallbackObject handle callback callback
MATLAB handle
CallbackObject root read-only
callback
CurrentFigure root CurrentAxes CurrentObject
callback
callback callback
callback
callback CreateFcn DeleteFcn ResizeFcn
figure gcbo callbacks
CurrentFigure root CurrentObject CurrentAxes figure
CallbackObject root
callbacks gcbo [ ]
gcf
handle (gcf=Get current figure )
h = gcf
gco
handle current object (gco = get current object)
h = gco
h = gco(figure_handle)
h =
146.0001
handle
handle
1. Figure Object
2. Axes Object
3. Uicontrol Object
4. Uimenu Object
5. UiContextMenu Object
MATLAB Reference Book I Reference
Book II Using Graphic Manual
GUI MATLAB
MATLAB
figure(h)
handle h h handle
handle h h
MATLAB handle h
handle h h error
handle
MATLAB handle
MATLAB
structure arrays cell arrays get set gcf
handle
set(0,'DefaultFigureProperty',PropertyValue...)
Property PropertyValue
set get
Figure No. n, n : on
Resize : on, off
: on
SelectionHighlight : on, off
: on
Visible : on, off
: on
WindowStyle : normal, modal
: normal
(Controlling the Colormap)
Colormap colormap : m x 3
RGB
: jet colormap
Dithermap Colormap truecolor : m x 3
data RGB
pseudocolor : colormap
DithermapMode MATLABdithermap : auto, manual
: manual
FixedColors colormap : m x 3
RGB read only
MinColormap : scalar
: 64
ShareColors MATLAB color table on, off
slots : on
(Specifying the Renderer)
BackingStore off screen pixel buffering : on, off
: on
DoubleBuffer : on, off
: off
Renderer : painters, zbuffer,
OpenGL
:
MATLAB
CurrentPoint : 2-element
[x-coord, y-coord]
CreateFcn : string
: string
DeleteFcn : string
: string
Interruptible : on, off
: on ()
KeyPressFcn : string
: string
ResizeFcn : string
: string
UIContextMenu context menu : handle Uicontrextmenu
WindowButtonDownFcn : string
: string
WindowButtonMotionFcn : string
: string
WindowButtonUpFcn : string
: string
(Controlling Access to Objects)
IntegerHandle handle : on, off
: on (handle
)
HandleVisibility handle : on, callback, off
: on
HitTest : on, off
( : on
CurrentObject )
NextPlot : add, replace,
replacechildren
: add
(Defining the Pointer)
Pointer : crosshair, arrow,
watch, topl, topr, botl, botr,
circle, cross, fleur, left,
right, top, bottom,
fullcrosshair, ibeam,
custom
: arrow
PointerShapeCData : 16-by-16 matrix
: Pointer
custom
PointerShapeHotSpot active spot : 2-element
[row, column]
: [1,1]
(Properties That Affect Printing)
InvertHardcopy : on, off
: on
PaperOrientation : portrait, landscape
: portrait
PaperPosition : 4-element
[left, bottom, width, height]
set get
axes object
: auto
TickLength : [2-D 3-D]
: [0.01 0.025]
two-element vector
Visible : on, off
: on
XGrid, YGrid, ZGrid grid : on, off
: off
(General Information About the Axes)
Children Handles images, lights, lines, patches, : handles
surfaces text
CurrentPoint : 2x3
HitTest current object : on, off
: on
Parent Handle figure : figure
handle
Position figure : [left bottom width
Height]
: [0.1300 0.1100
0.7750 0.8150]
Selected : on, off
: on
Tag : any string
: '' ( string )
Type : string 'axes'
Units : inches, centimeters,
'Position' Characters, normalized,
Points, pixels
: Normalized
UserData : any matrix
: [ ] ()
(Selecting Fonts and Labels)
FontAngle : normal, italic, Oblique
: normal
FontName Helvetica :
Courier
: Helvetica
FontSize :
: 10
FontUnits : points, normalized,
FontSize inches, centimeters, pixels
: points
FontWeight : normal, bold, light,
demi
: normal
Title Handle title : handle
title
XLabel, Handles : Handles
YLabel,
ZLabel
CameraViewAngle : 0180
:
MATLAB
CameraViewAngleMode MATLAB : auto, manual
: auto
Projection projection : orthographic,
perspective
: orthographic
(Controlling the Axes Aspect Ratio
DataAspectRatio :
[dx dy dz]
:
MATLAB
DataAspectRatioMode MATLAB : auto, manual
: auto
PlotBoxAspectRatio :
[dx dy dz]
:
MATLAB
PlotBoxAspectRatioMode MATLAB : auto, manual
: auto
Callback (Controlling Callback Routine Execution)
BusyAction : cancel, queue
: queue
ButtonDownFcn : string
: string
CreateFcn : string
: string
DeleteFcn : string
: String
Interruptible : on, off
: on
UIContextMenu contextmenu : handle
Uicontextmenu
(Specifying the Rendering Mode)
DrawMode (rendering) : normal, fast
: normal
1.
M-file
h(4)=axes('Position',[5 0 .4 .4]);
sphere
m-file
2. X Y
Y
X X
Y x
XAxisLocation YAxisLocation X
Y 2
XaxisLocation and YAxisLocation
X Y
2
x-y
x1=linspace(0,30);
y1=sin(x1).^exp(-x1/10);
hl1= line(x1,y1,'color','r');
ax1= gca;
set(ax1,'Xcolor','r','Ycolor','r');
grid on
x y none
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k','YColor','k');
x2=x1/10;
y2=100*sin(x2/30).*exp(-x2);
hl2 = line(x2,y2,'Color','k','Parent',ax2);
grid on
0.8
1.2
0.6
1
0.4
0.2 0.8
0 0.6
-0.2
0.4
-0.4
0.2
-0.6
-0.8 0
0 5 10 15 20 25 30
grid grid on
grid
grid
grid grid grid
x y
xinc = (xlimits(2)-xlimits(1))/6;
yinc = (ylimits(2)-ylimits(1))/7;
tick mark
set(ax1,'XTick',[xlimits(1):xinc:xlimits(2)],...
'YTick',[ylimits(1):yinc:ylimits(2)])
0.7429 1.2
0.4857 1
0.2286 0.8
-0.0286 0.6
-0.2857 0.4
-0.5429 0.2
-0.8 0
0 5 10 15 20 25 30
trick mark y
limit y 7 y 8 trick mark
7 1 1.1
2.1 7 0.3
ylimits = [-1.0 1.1];
set(ax1,'YLim',ylimits);
yinc = (ylimits(2)-ylimits(1))/7;
set(ax1,'XTick',[xlimits(1):xinc:xlimits(2)],...
'YTick',[ylimits(1):yinc:ylimits(2)])
0.8 1.2
0.5 1
0.2 0.8
-0.1 0.6
-0.4 0.4
-0.7 0.2
-1 0
0 5 10 15 20 25 30
0.8 1.2
0.5 1
0.2 0.8
Y1 value
Y2 value
-0.1 0.6
-0.4 0.4
-0.7 0.2
-1 0
0 5 10 15 20 25 30
X1 value
13.3 Uicontrol
user interface control object
handle = uicontrol(parent)
handle = uicontrol(...,'PropertyName',PropertyValue,...)
1. Check boxes
2. Editable text
3. Frames
4. List boxes
5. Pop-up menus
6. Push buttons
GUI
uicontrol
uicontrol
1. Check boxes
check box
3. Frames
Frames
uicontrol
uicontrol Frames callback
uicontrols frames Frames
frame uicontrols
uicontrols frame frame
Stacking order uicontrols
frame frame
4. List boxes
String
Min Max Value
Value MATLAB
callback list box
Value
5. Pop-up menus
String
Pop-up menus
String
6. Push buttons
Push buttons
7. Radio buttons
check boxes
Radio button Radio button
radio button
8. Sliders
slider
slider
uicontrol structures
cell arrays arguments handle
set get
Uicontrol children figures axes
uicontrol objects
push button
h = uicontrol('Style', 'pushbutton', 'String', 'Clear',...
'Position', [20 150 100 70], 'Callback', 'cla');
uicontrol
hsv, hot, cool gray String
|
Callback M-file setmap
M-file callback
M-file callback setmap
M-file M-file setmap
val = get(hpop,'Value');
if val ==1
colormap(hsv)
elseif val ==2
colormap(hot)
elseif val ==3
colormap(cool)
elseif val ==4
colormap(gray)
end
13.4 Uimenu
uimenu('PropertyName', PropertyValue,...)
uimenu(parent, 'PropertyName', PropertyValue,...)
handle = uimenu('PropertyName', PropertyValue,...)
handle = uimenu(parent,'PropertyName',PropertyValue,...)
uimenu
uimenu context menu
Handle = uimenu('PropertyName',PropertyValue,...)
handle
handle = uimenu(parent,'PropertyName',PropertyValue,...)
MATLAB
uimenu
property name property value structures cell arrays
input arguments Callback uimenu
MATLAB Uimenus
WindowStyle normal figure object
uimenu WindowStyle modal
Workspace figure window
(save) workspace MATLAB
Ctrl Q Quit
accelerator key
f = uimenu('Label','Workspace');
uimenu (f,'Label','New Figure','Callback','figure');
uimenu (f,'Label','Save','Callback','save');
uimenu (f,'Label','Quit','Callback','exit',...
'Separator','on','Accelerator','Q');
context menu line
M-file
% context menu
cmenu = uicontextmenu;
% context menu
hline = plot(1:10,'UIContextMenu',cmenu);
% callbacks context menu
% 3
cb1 = ['set(hline, ''LineStyle'', ''--'')'];
cb2 = ['set(hline, ''LineStyle'', '':'')'];
cb3 = ['set(hline, ''LineStyle'', ''-'')'];
% context menu
item1 = uimenu(cmenu, 'Label', 'dashed', 'Callback', cb1);
item2 = uimenu(cmenu, 'Label', 'dotted', 'Callback', cb2);
item3 = uimenu(cmenu, 'Label', 'solid', 'Callback', cb3);
M-file
children Axes
MATLAB
FIG-file
GUI
M-file GUI callback
callback sub function M-file M-file
GUI Application M-file
Application M-file
GUI FIG-file
Layout Editor
GUI
Tool Application Options
Resize Behavior
GUI
MATLAB GUIDE 3
Non-Resizable (default)
Proportional GUI MATLAB
GUI GUI
User-Specifide GUI
GUI GUI
GUI
GUI
Proportional
Proportional
GUI
User-Specify
Command-Line Accessibility
GUI axes
GUI axes
GUI GUIDE Command-Line Accessibility
n Application M-file
Generate Callback Function Prototype GUIDE Application
Option GUIDE sub function application M-file GUI
( frame Static text) GUEDE sub function
sub function GUIDE sub
function callback context
callback sub function
function object.Tag_Callback(h,eventdata,handles.varagin)
arguments
h handle callback
eventdata
handles structure handle GUI
file tag handle
GUI callback
MATLAB
varargin variable-length callback function
push button Tag pushbutton1
GUIDE sub function application
function pushbutton1_Callback(h,evendata,handles,varargin)
Mygui(pushbutton1_callback,gcbo,[],guidata(gcbo))
MYGUI(pushbutton1_callback,gcbo,[],guidata(gcbo),gx1,gx2)
GUI
GUI
MATLAB GUI
MATLAB GUI
fig = openfig(mfilename,reuse)
fig = openfig(mfilename,new)
application M-file
p input
GUIDE application option
MATLAB
GUI
GUI callback uiresume
guide mygui.fig
Note GUI
Tag GUI Activate Figure
Layout Editor
context menu
context menu subfunction application M-file
callback routine
Context figure
Alignment Tool
(select) component palette
14.4
GUI Property
Inspector
Property Inspector
Property Inspector Tools
Inspect property Edit
Inspect Properties context
Property Inspector
Mixed
MATLAB
Menu bar object - figure menu bar
Context Menu -
Menu Editor
Menu Editor Layout Editor Toolbar Edit Menu bar Layout Menu Editor
UI MENU Property
Lable (), Tag () Seperator () Checked
Menu property () Callback menu
p callback
callback
MATLAB callback Menu Editor
print-dsp Subfunction
Application- M file GUIDE UI control callback
Name_of_subfunction subfuncton
gcbo handle
[]
guidata (gcbo) handles GUI
q Context Menu
Context Menu
Menu Editor context menu
input Subfunction
h handle
eventdata
handles structure field handle
GUI field Tag GUI
3
Figure Tag figure1 handle
1.00256
Push Buttom Tag ObjectTag handle 5.00123
Slider Tag slider1 handle 6.00301
handles.ObjectTag 5.00123
handles.slider1 6.00301
Command Window
Callback Subfuction
o Application M file
2. M-file Subfunction
callback
GUI
Switchyard Code
GUIDE
fig = openfig(mfilename,'reuse');
% Use system color scheme for figure:
set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));
if nargout > 0
varargout{1} = fig;
end
try
[varargout{1:nargout}]=feval(varargin{:});%FEVAL switchyard
catch
disp(lasterr);
end
end
code