Professional Documents
Culture Documents
. , MSc
: .
MATLAB &
, .
, MSc, 9
...
.
... (.. . . ).
-1-
MATLAB &
1.1 Matlab
1.2 Matlab
1.3 Matlab
1.4 Matlab
12
1.5 - MatLab
13
MATLAB
2.1 Matlab
15
2.2 Matlab
21
2.3
37
MATLAB
40
42
3.3
45
3.4
46
MATLAB
4.1
52
4.2
57
4.3
62
4.4
64
-2-
MATLAB &
4.5
70
MATLAB
5.1 Matlab
73
5.2 Matlab
81
85
86
88
(script file)
89
-3-
MATLAB &
1.1 Matlab
1.2 Matlab
1.3 Matlab
1.4 Matlab
1.5 - MatLab
1.
1.1 MATLAB
MATLAB
(numerical computations).
,
animations. , MATLAB
, .
,
MATLAB
MATrix LABoratory.
MATLAB ,
,
, , (
), . ,
,
, :
animations.
-4-
MATLAB &
.1
MATLAB.
, , ,
(state-of-the-art algorithms).
,
.
,
.
MATLAB ,
,
(symbolic computation), (image processing),
(statistics), (control system design),
(neural networks), (fuzzy logic).
(
50).
-5-
MATLAB &
MATLAB
MATLAB
-2-D
- C, Java,
-3-D
Fortran VB.Net
- &
- &
-Animation
- & Video
- &
1: Matlab
MATLAB (matrix)
(array).
.
MATLAB
, .
-6-
MATLAB &
,
.
1.2 MATLAB
MATLAB .
Windows,
, UNIX, Sun Solaris, Linux MAC
OS 10.3.
, MATLAB
, .2
.
MATLAB desktop
Figure window
(Workspace)
(Current directory)
Editor window
2: Matlab
-7-
MATLAB &
(Command Window): .
(>>, MATLAB command prompt).
, ,
, ,
( ). ,
MATLAB,
,
.
(Current directory):
MATLAB, ,
(directory) .
,
( ),
,
( , , - File).
(Workspace):
,
.
.
,
. MATLAB
,
, .
(Command History):
, ,
, .
,
,
.
, .
2. (Figure Window)
,
, ,
, . ,
.
MATLAB (MATLAB 7).
-8-
MATLAB &
3. (Editor Window)
, , ,
, MFiles.
(text editors), MATLAB
, .
,
(Start),
MLAB,
.
1.3 MATLAB
MATLAB ,
, ,
. ,
MATLAB
MATLAB (. 5.2).
,
,
. :
: ,
, ,
.
,
, .
(dimensioning) ().
,
(real number) ,
MATLAB
,
,
.
-9-
MATLAB &
: MATLAB
,
.
.
(,
. MATLAB
31 .
,
. :
+, -, *, ^, /, \, =, ~, <, >, &, |, :, (, ), [, ], ., %, !
, MATLAB.
,
. (constant values)
. pi,
eps
(eps=2.2204e-016),
,
.
(output display):
(
).
, .
(;) MATLAB
- 10 -
MATLAB &
,
(graphics and online help commands).
(;) .
(output
format): MATLAB
,
output format.
10.
31.4159
format short
(scaled
fixed
point
format
with 5 digits)
31.1416e+001
format short e
format long
(scaled
fixed
point
format
with 15 digits)
31.41592653589793e+001
format long e
format short g
format long g
format hex
403f6a7a2955385e
(hexadecimal format)
3550/113
format rat
(approximation
by
ratio
of
small integers)
31.42
format bank
- 11 -
MATLAB &
: MATLAB ,
. ()
() ,
.
()
() .
, ,
, ,
(Command
History).
, (copy)
(paste)
.
1.4 MATLAB
MATLAB .
,
.
-files: ASCII text files, .m
. : script
files function files (. 3.1 3.2). ,
MATLAB M-files.
M-files.
M-flies,
.
at-files: binary data-files, .mat
. T MATLAB
save. ,
- 12 -
MATLAB &
. ,
MATLAB load.
Fig-files: binary figure-files, .fig
. T MATLAB
,
File menu Save Save As
saveas .
MATLAB ,
.
open filename.fig.
P-files: M-files,
.p MATLAB.
pcode. ,
(M-file) ,
p-file.
Mex-files: MATLAB
, Fortran C.
.mex
MATLAB.
1.5 MATLAB
,
, MATLAB.
help
helpwin
helpdesk
help topic
demo
MATLAB,
,
(Workspace)
who
(Workspace)
- 13 -
MATLAB &
whos
(Workspace),
what
clear
Clear x, y, z
clear all
mlock fun
munlock
(Workspace),
() x, y, z
fun, clear,
fun, clear,
fun
clc
,
(Directory)
pwd
directory
cd
directory
dir
directory
mkdir
copyfile
directory
computer
date
ver
/,
MATLAB, /
quit
MATLAB
exit
MATLAB
- 14 -
MATLAB &
MATLAB
2.1 Matlab
2.2 Matlab
2.3
2. MATLAB
2.1 MATLAB
, MATLAB
(, ,
) ,
,
, .
/\
ans =
5
>> 11-5
ans =
6
>> 11*8
- 15 -
MATLAB &
ans =
88
>> 12/3
ans =
4
>> 3\12
ans =
4
>> 2^6
ans =
64
MATLAB ,
.
,
.
>> (15-6)*5+3
ans =
48
>> (3-1)/(2*6+9)
ans =
0.095
,
:
,
,
(
)
( ).
- 16 -
MATLAB &
MATLAB ( )
.
:
=
>> x=3
x=
3
>> y=11-6
y=
5
>> z=y-x
z=
2
(=)
, .
,
.
, ,
(=) ('').
>> a='aris'
a=
aris
>> b=''
b=
MATLAB (%).
, ,
, .
- 17 -
MATLAB &
>> c=11+6 %.
(%)
c=
17
MATLAB,
,
.
(
MATLAB rad),
..
.
.
sqrt
abs
sin
cos
tan
cot
asin
acos
atan
acot
exp
ex
log
log10
>> sqrt(4)
4 =2
ans =
2
>> sin(56) % rad
ans =
-0.5216
>> tan(0.5)
- 18 -
MATLAB &
ans =
0.5463
a cos(0.5) = 1.0472
>> acos(0.5)
ans =
1.0472
e4 = 54.5982
>> exp(4)
ans =
54.5982
ln(4) = 1.3863
>> log(4)
ans =
1.3863
log(4) = 0.6021
>> log10(4)
ans =
0.6021
o MATLAB ,
.
,
.
i j,
.
>> i
ans =
0 + 1.0000i
>> j
ans =
0 + 1.0000i
:
a+bi a+b*i
- 19 -
MATLAB &
MATLAB ,
i .
j.
MATLAB
.
>> x=2-3i
x=
2.0000 - 3.0000i
>> y=16-8i
y=
16.0000 - 8.0000i
>> x-y
ans =
-14.0000 + 5.0000i
>> real(x-y)
ans =
-14
>> imag(x-y)
ans =
>> 10*y
ans =
1.6000e+002 -8.0000e+001i
>> x^2
ans =
-5.0000 -12.0000i
- 20 -
MATLAB &
2.2
MATLAB
(
,
MATLAB ).
,
, ...
(,),
(;) .
([..]).
, ,
, ,
.
,
.
>> A=[1 2 5;6 8 7]
A=
1
>> C=[1;2;3]
1 2 5
A=
6 8 7
1 4 6
B=
7 1 3
1
C = 2
3
C=
1
2
3
D = 1 2 3
>> D=[1 2 3]
D=
1
E = 1 3 5 sin(2.3) 5 200
E=
0.3333
3.7285
70.7107
- 21 -
MATLAB &
T Matlab
1.0000
2.0000 + 5.0000i
2+5 i
1
A=
1.2-5 i 56
(Command window),
(...)
.
>> H=[1 2 3;...
5 6 7;...
8 9 10]
H=
1
10
1 2 3
A = 5 6 7
8 9 10
,
, MATLAB
. ,
. , ,
,
.
, .
>> I=[]
I=
[]
>> J=[1 2 3;5 6]
have
the
same
number
of
columns.
- 22 -
MATLAB &
, MATLAB
(vector),
, ,
(increment) .
, .
.
>> A=0:10:30
A=
10
10
20
30
: 30
>> B=100:105
B=
100
1 ( )
100
101
102
103
104
105
: 105
>> C=5:-3:-9
C=
-3
-1
-4
-7
: -9
>> D=0:pi:7
D=
=3.14
3.1416
6.2832
: 7
>> E=1:-exp(1):-2*(1+2)
E=
e1 = 2.7183
1.0000
-1.7183
-4.4366
: -6
,
, ()
. , MATLAB ,
, .
- 23 -
MATLAB &
>> K(2,3)=2
K=
MATLAB
,
,
/ ,
,
- ,
(scalar numbers) ..
.
>> clear all
>> A=[1 2 2;3 4 4;5 6 6]
3 x 3
A=
1
>> A(1,3)=7
A=
, (1,3)
>> B=A(2:3,1:3)
B=
, 2
(2:3)
(1:3)
>> B(2,:)=[]
B=
, 2
[(:,2)
...
x ,
- 24 -
MATLAB &
(=), 2
]
>> B(:,2)=[]
B=
, 2
[(2,:) = ...
x ,
(=), 2
,
]
,
-,
, ,
, .
(:),
.
.
>> C=[4 5 3 12 6;7 2 1 13 28;...
15 36 45 8 10;12 22 32 42 9;...
( )
11 21 27 33 40]
C=
4
12
13
15
36
45
10
12
22
32
42
11
21
27
33
40
>> v=[1 4 5]
1 x 3
v=
. (2 ,
>> C(v,:)
- 25 -
3)
MATLAB &
ans =
12
12
22
32
42
11
21
27
33
40
>> clear C
>> C=[4 5 3 12 6;7 2 1 13 28;...
15 36 45 8 10;12 22 32 42 9;...
( )
11 21 27 33 40]
C=
4
12
13
28
15
36
45
10
12
22
32
42
11
21
27
33
40
>> C(:,v)
ans =
12
13
28
15
10
12
42
11
33
40
, MATLAB
,
() ,
()
, .
>>C=[4 5 3;7 2 1;15 36 45]
3 x 3 (
C=
15
36
45
>> B=C(:)
B=
4
7
- 26 -
MATLAB &
15
5
2
36
3
1
45
>> clear C
>> C=[4 5 3 12;7 2 1 13;...
4 x 4 (
15 36 45 8;12 22 32 42]
C=
4
12
13
15
36
45
12
22
32
42
>> reshape(C,8,2)
ans =
15
45
12
32
. :4 x 4
12
. : 8 x 2
13
(4 x 4 = 8 x 2 = 16)
36
22
42
>> reshape(C,2,8)
ans =
. :4 x 4
15
36
45
12
12
22
32
13
42
. : 2 x 8
(4 x 4 = 2 x 8 = 16)
, MATLAB
.
,
(:),
,
.
- 27 -
MATLAB &
A=
( )
-,
>> c=[9;10;11];
-,
>> F=[A;b]
F=
>> G=[A c]
G=
10
11
, , MATLAB
,
. .
>> clear all
>> A=[1 2 3;4 5 6;7 8 9];
3 x 3
>> B=A'
B=
- 28 -
MATLAB &
>> v=u'
v=
0
1
2
3
4
(, ,
, ),
,
.
, ,
:
/\
/
\
^b (b:scalar)
, (\)
(/), .
, (/)
(1),
(2).
y C = d y = d/C ( )
(1)
A x = b x = A /b ( )
(2)
- 29 -
MATLAB &
.
>> clear all
>> A=[1 2 3;4 5 6;7 8 9];
3 x 3
3 x 3
>> C=A+B
C=
11
13
15
17
19
21
23
25
27
>> D=A-B
D=
-9
-9
-9
-9
-9
-9
-9
-9
-9
>> E=A*B
E=
84
90
96
201
216
231
318
342
366
>> F=A^4
F=
7560
9288
11016
17118
21033
24948
26676
32778
38880
>> G=(2*sin(4.2))*B
G=
, MATLAB
, .
- 30 -
MATLAB &
, u ,
, , :
u = [u1 u2 u3 u4 ]
v = [v1 v2 v 3 v 4 ]
u v = [u1 v1 u2 v2 u3 v 3 u4 v 4 ]
,
. (
). ,
,
(forNext), MATLAB
.
,
,
.
.*
/\
./
.\
.^
3 x 3
3 x 3
>> C=A.*B
C=
10
22
36
52
70
90
112
136
162
- 31 -
MATLAB &
>> D=2./A
D=
2.0000
1.0000
0.6667
0.5000
0.4000
0.3333
0.2857
0.2500
0.2222
>> E=2.\A
E=
0.5000
1.0000
1.5000
2.0000
2.5000
3.0000
3.5000
4.0000
4.5000
>> F=B.^A
F=
1.0e+011 *
0.0000
0.0000
0.0000
0.0000
0.0000
0.0001
0.0027
0.0698
1.9836
MATLAB ,
,
.
,
, , .
,
.
eye(m,n)
mxn
zeros(m,n)
mxn
ones(m,n)
mxn
rand(m,n)
mxn
0 1
randn(m,n)
mxn
Gauss
- 32 -
MATLAB &
,
linspace(a,b,c)
a, b
c-2 ,
,
diag(v)
diag(A)
.
>> eye(3,2)
3x2 ,
ans =
0
3x2
>> zeros(3,2)
ans =
0
0
3x2
>> ones(3,2)
ans =
1
>> rand(3,3)
3x3
ans =
0.9501
0.4860
0.4565
0.2311
0.8913
0.0185
0.6068
0.7621
0.8214
>> randn(3,3)
0-1
3x3
- 33 -
MATLAB &
ans =
-0.4326
0.2877
1.1892
-1.6656
-1.1465
-0.0376
0.1253
1.1909
0.3273
Gauss
1x3
>> diag(v)
ans =
10
11
12
3x3
>> diag(A)
ans =
9
>> linspace(1,10,3)
ans =
1, 10
1.0000
5.5000
10.0000
3-2
, ,
.
length(v)
size(A)
ndims(A)
numel(A)
max(A)
- 34 -
MATLAB &
min(A)
mean(A)
std(A)
trace(A)
rot90(A)
fliplr(A)
flipud(A)
tril(A)
triu(A)
inv(A)
900
,
.
>> clear all
>> A=[10 11 12;13 14 15;16 17 18];
3x3
>> size(A)
ans =
3
>> ndims(A)
ans =
2
>> numel(A)
ans =
- 35 -
MATLAB &
>> max(A)
ans =
16
17
18
>> min(A)
ans =
10
11
12
>> mean(A)
ans =
13
14
15
>> std(A)
ans =
>> trace(A)
ans =
42
900
>> rot90(A)
ans =
12
15
18
11
14
17
10
13
16
>> fliplr(A)
ans =
12
11
10
15
14
13
18
17
16
>> flipud(A)
ans =
16
17
18
13
14
15
10
11
12
>> tril(A)
ans =
- 36 -
MATLAB &
10
13
14
16
17
18
>> triu(A)
ans =
10
11
12
14
15
18
3x3
>> inv(C)
ans =
0.2005
0.0433
0.0638
0.0433
0.1116
0.0592
0.0638
0.0592
-0.0706
1x4
>> length(v)
ans =
2.3
, ,
.
,
.
,
MATLAB.
, ,
,
det(A).
3x3
>> det(A)
ans =
- 37 -
MATLAB &
-5
,
, Gauss.
.
,
:
x1 + 2 x2 + 3 x3 = 4
2 x1 + 3 x2 + 4 x3 = 5
4 x1 + 2 x2 + 5 x3 = 1
1 2 3 x1 4
1
2 3 4 x2 = 5 A x = b x = A b
4 2 5 x3 1
0.8000
0.2000
-1.2000
1.4000
-0.4000
1.6000
-1.2000
0.2000
>> C*b %
ans =
-1.4000
1.8000
0.6000
Gauss
- 38 -
MATLAB &
-1.4000
1.8000
0.6000
MATLAB :
x3 15x = 4 1 x3 + 0 x2 15 x 4 = 0
- 39 -
MATLAB &
MATLAB
3. MATLAB
MATLAB
,
.
,
C. ,
MATLAB
,
,
.
MATLAB M-Files. M-Files
ASCII (text files),
.m
. M-Files
(editor
or word processing application).
(-file Editor).
M-files. script files
function files.
MATLAB. (Command
window), , .m,
- 40 -
MATLAB &
(prompt).
,
, .
, script files
(global variables),
(workspace), ,
,
.
3: Matlab Editor
, ,
MATLAB ( )
.
script files ,
.
, .
script files.
1: , M-file
, .
- 41 -
MATLAB &
(Workspace). M-file, ,
,
MATLAB,
, .
4: ,
, .
,
MATLAB.
,
,
, ... 2003
.
MATLAB.
- 42 -
MATLAB &
,
.
, ,
(script file).
function [output variables] = function _name (input variables);
(function _name)
M-file, .m,
. ,
spectra, ,
, spectra.m.
,
, ,
.
(definition line) ,
:
Function definition line
File name
kostas.m
angle.m
theta.m
function []=spectra(t);
spectra.m
function spectra(t);
spectra.m
(function).
.
,
.
function [out1,out2]=functionname (in1,in2)
H1 line
% , ,
- 43 -
MATLAB &
a= triangle;
b= square;
, (%),
, .
,
, MATLAB,
, , H1 Line,
,
directory contents.m.
,
[].
,
, (=)
.
,
,
.
.
, ,
(Workspace), .
.
MATLAB
,
, .
:
function [maxM, maxV] = momentofbeam (l,p,q);
,
, :
- 44 -
MATLAB &
, .
[M,V]= momentofbeam(length, load, [5:20]);
length, loadp ,
,
loadq .
[M,V]= momentofbeam(3,100,10);
3.3
MATLAB ,
, .
xor.
&
xor
,
,
,
(1- 0-). ,
, MATLAB ,
.
<
<=
>
>=
==
~=
- 45 -
MATLAB &
.
>> clear all
>> x=20;
>> y=30;
>> z=x>y
x y
z=
0
>> z=x<=y
x y
z=
1
>> z=x==y
x y
z=
0
>> t=x~=y
x y
t=
MATLAB, ,
,
21 39.
>> clear all
>>A=[10,15,20;25,30,35;40,45,50];
3x3
21
39
C=
21, 22 23
- 46 -
MATLAB &
3.4
,
. ,
MATLAB.
for loops
for
.
:
for
end
.
, MATLAB
.
for
.
>> clear all
>> for i=1:1:10
length=1+i*10;
end
load=2*m/5;
end
,
for. ,
.
- 47 -
MATLAB &
3x3
>> s=0;
for j=1:3
s=s+A(i,j)
end
end
s=45
while
while ,
,
. ,
,
, . ,
,
. ( )
.
,
, , while
. ,
Ctrl + c.
:
while
end
while ,
,
, .
- 48 -
MATLAB &
>> num = 0;
num
>> eps = 1;
eps
while
eps=eps*0.5
num=num+1
end
num = 53
num
>> eps=2*eps
eps = 2.2204e-016
if
if ,
, .
:
if 1
1
elseif 2
2
:
:
elseif n
n
else
(n+1)
end
i=1,2,...,n
, i=1,2, n.
n+1 ,
i=1,2,...,n .
,
- 49 -
MATLAB &
if,
.
if
... 2003,
,
.
... 2003,
(,
),
seismiczone
>> if seismiczone==1
a=0.12;
elseif seismiczone==2
a=0.24;
elseif seismiczone==3
a=0.36;
end
>> a
a=
0.3600
switch-case-otherwise
.
. ,
.
switch-caseotherwise if.
>> seismiczone='II';
seismiczone
switch
case 'I'
a=0.12
case 'II'
a=.24
a=0.36
end
- 50 -
MATLAB &
a=
0.2400
,
,
, .
break
if i*5>50
if
break
if
end
if
c=i/10+i;
end
>> c
c=
11
error
error (message)
(script files)
(function file).
,
.
- 51 -
MATLAB &
MATLAB
4.1
4.2
4.3
4.4
4.5
4. MATLAB
MATLAB ,
, animations.
,
,
,
,
MATLAB.
,
- .
4.1
plot.
( ).
:
plot (xvalues, yvalues, style option)
- 52 -
MATLAB &
,
:
xvalues, yvalues: ,
, x y , .
style option: plot
, ()
.
, :
color_linestyle_markerstyle
x
y . ,
MATLAB. MATLAB
,
.
, ,
( ).
style option
style
option
plot
, ,
.
plot.
Style option / Color
--
x x
-.
+ +
p
h
^
- 53 -
MATLAB &
v
>
<
plot .
plot (x, y, r)
(y) vs (x)
plot (x, y, :)
(y) vs (x) ,
(y) vs (x)
plot (x, y, +)
(y) vs (x) , +
style option
,
.
,
,
(, ) .
:
xlabel(text), ylabel(text), title(text), text
,
,
,
,
.
, , ,
, ,
.
legend.
,
. legend
,
(,), ,
.
- 54 -
MATLAB &
, ,
.
.
-1
. :
FontName x Courier, Times, Helvetica, Symbol,
FontSize x 12, 13, 14,
FontAngle x normal, italic, oblique
FontWeight x light, normal, demi, bold
HorizontalAlignment x left, right, center
VerticalAlignment x top, cap, middle, baseline, bottom
, MATLAB
, zoom in
zoom out.
:
axis([xmin, xmax, ymin, ymax])
,
. ,
axis
, .
axis(equal)
axis(square)
axis(normal)
- 55 -
MATLAB &
axis(axis)
axis(off)
, MATLAB
,
.
:
grid on grid off
,
MATLAB , ,
.
plot,
figure()
,
, .
, , ,
subplot(m,n,p).
m x n ,
. ,
p, 1,2,...
, ,
.
subplot
plot,
.
MATLAB, ,
, plot
editor.
- 56 -
MATLAB &
4.2
, ,
MATLAB.
plot
>> a=linspace(0,2*pi,100);
>> x=cos(a);
>> y=sin(a);
>> plot(x,y,kx)
>>axis(equal)
>>xlabel(x,FontSize,14,FontWeight,demi)
>>ylabel(y,FontSize,14,FontWeight,demi)
fplot
>>fplot('x*sin(x)',[0 50*pi])
>>ylabel('y','FontSize',14,'FontWeight','demi')
>>xlabel('x','FontSize',14,'FontWeight','demi')
>>title('fplot diagram','Fontweight','bold')
- 57 -
MATLAB &
loglog
>> z=linspace(0,2*pi,100);
>> x=5*exp(z);
>> y=155+36*exp(2*z);
>> loglog(x,y,'m+')
>> title('loglog diagram','Fontweight','bold')
>> ylabel('y','FontSize',14,'FontWeight','bold')
>> xlabel('x','FontSize',14,'FontWeight','bold')
semilogx
>> z=linspace(0,2*pi,100);
>> x=5*exp(z);
>> y=z;
>> semilogx(x,y,'r>')
>> xlabel('x','FontSize',14,'FontWeight','bold')
>> ylabel('y','FontSize',14,'FontWeight','bold')
>> title('semilogx diagram','Fontweight','bold')
- 58 -
MATLAB &
semilogy
> z=linspace(0,2*pi,100);
>> semilogy(z,exp(z),'b^')
>> title('semilogy diagram','Fontweight','bold')
>> ylabel('y','FontSize',14,'FontWeight','bold')
>> xlabel('x','FontSize',14,'FontWeight','bold')
hist
>> z=randn(200,1);
>> hist(z)
- 59 -
MATLAB &
barh
>> magnitude=char('<=6.25','6.25-6.5','6.5-6.75',...
'6.75-7.00','7.00-7.25','7.25-7.50','7.50-7.75');
>> earthquakes=[16;13;13;15;9;2;1];
>> barh(earthquakes)
>> for i=1:7,
gtext(magnitude(i,:));
end
>> xlabel('Number of earthquakes in Greece','FontSize',14,'FontWeight','demi')
>> Title('barh','Fontweight','bold')
pie
>> magnitude=char('<=6.25','6.25-6.5','6.5-6.75',...
'6.75-7.00','7.00-7.25','7.25-7.50','7.50-7.75');
>> earthquakes=[16;13;13;15;9;2;1];
>> pie(earthquakes)
>> for i=1:7,
gtext(magnitude(i,:));
- 60 -
MATLAB &
end
>> Title('pie diagram','Fontweight','bold')
fill
>> z=linspace(0,2*pi,500);
>> r=sqrt(abs(5*sin(10*z)));
>> x=r.*cos(z);
>> y=r.*sin(z);
>> fill(x,y,'y')
>> title('fill diagram','Fontweight','bold')
>> xlabel('x','FontSize',14,'FontWeight','demi')
>> ylabel('y','FontSize',14,'FontWeight','demi')
>> axis('square')
- 61 -
MATLAB &
4.3
MATLAB ,
( ) .
,
,
.
plot3. plot,
,
plot3.
,
:
plot3 (xvalues, yvalues, zvalues, style option)
,
plot
.
, ,
, ,
.
,
, . ,
,
. ,
.
. ,
x-y
y (azimuth). ,
x-y
(elevation).
- 62 -
MATLAB &
4:
x-y
.
y
x-y.
, , .
:
view (azimuth, elevation)
-37.5 300
.
.
,
,
. :
rotate3d (x0)
- 63 -
MATLAB &
mesh surf
,
( z=f(x,y)),
,
, .
,
, ,
mesh
(meshz, meshc, meshgrid).
mesh ,
.
patches. surf,
(surfc, surfl)
(shading flat, shading interp, shading faceted), MATLAB
,
.
, , ,
z, ,
.
.
contour, ()
pcolor, ,
.
4.4
,
MATLAB.
plot3
>> z=linspace(0,100*pi);
>> c=exp(-2*z/32);
>> x=c.*cos(z);
>> y=c.*sin(z);
>> plot3(x,y,z)
>> view(15,-10)
>> title('plot3 diagram')
- 64 -
MATLAB &
fill3
>> X=[0 0 0 0;2 2 -2 -2;...
2 -2 -2 -2;];
>> Y=[0 0 0 0;6 6 6 6;...
6 6 6 6];
>> Z=[0 0 0 0;2 2 -2 -2;...
-2 2 2 -2];
>> fillcolor=rand(3,4);
>> fill3(X,Y,Z,fillcolor)
>> view(120,35)
mesh
>> a=-6:0.3:6;
>> [X,Y]=meshgrid(a,a);
>> Z=cos(X).*cos(Y).*...
- 65 -
MATLAB &
exp(-sqrt(X.^2+Y.^2)/4);
>> mesh(Z)
>> title('mesh diagram')
>> zlabel('Axis z')
>> xlabel('Axis x')
>> ylabel('Axis y')
meshz
>> a=-6:0.3:6;
>> [X,Y]=meshgrid(a,a);
>> Z=cos(X).*cos(Y).*...
exp(-sqrt(X.^2+Y.^2)/4);
>> meshz(X,Y,Z)
>> ylabel('Axis y')
>> xlabel('Axis x')
>> zlabel('Axis z')
>> title('meshz diagram')
surf
- 66 -
MATLAB &
>> a=-6:0.3:6;
>> [X,Y]=meshgrid(a,a);
>> Z=cos(X).*cos(Y).*...
exp(-sqrt(X.^2+Y.^2)/4);
>> surf(X,Y,Z)
>> zlabel('Axis z')
>> ylabel('Axis y')
>> xlabel('Axis x')
>> title('surf diagram')
surfc
>> a=-6:0.3:6;
>> [X,Y]=meshgrid(a,a);
>> Z=cos(X).*cos(Y).*...
exp(-sqrt(X.^2+Y.^2)/4);
>> surfc(Z)
>> title('surfc diagram')
>> xlabel('Axis x')
>> ylabel('Axis y')
>> zlabel('Axis z')
- 67 -
MATLAB &
surfl
>> a=-6:0.3:6;
>> [X,Y]=meshgrid(a,a);
>> Z=cos(X).*cos(Y).*...
exp(-sqrt(X.^2+Y.^2)/4);
>> surfl(Z)
>> shading interp
>> ylabel('Axis y')
>> xlabel('Axis x')
>> zlabel('Axis z')
>> title('surfl diagram')
contour3
>> a=-6:0.3:6;
>> [X,Y]=meshgrid(a,a);
>> Z=cos(X).*cos(Y).*...
exp(-sqrt(X.^2+Y.^2)/4);
>> contour3(Z)
- 68 -
MATLAB &
pie3
>> earthquakes=[16;13;13;15;9;2;1];
>> magnitude={'<=6.25','6.25-6.5','6.5-6.75',...
'6.75-7.00','7.00-7.25','7.25-7.50','7.50-7.75'};
>> pie3(earthquakes,magnitude)
>> Title('pie3 diagram','Fontweight','bold')
sphere
>> [a,b,c]=sphere(30);
>> surf(a,b,c)
>> axis('square')
>> ylabel('Axis y')
>> xlabel('Axis x')
>> zlabel('Axis z')
- 69 -
MATLAB &
4.5
,
MATLAB
.
,
,
.
,
,
(Figure window).
, ,
Windows, (Save)
.fig, .
MATLAB .
(.bmp, .tiff, .jpeg, .jpg),
Save As ,
.
- 70 -
MATLAB &
5:
- 71 -
MATLAB &
MATLAB
5.1 Matlab
5.2 Matlab
5. MATLAB
MATLAB
/.
(importing data). ,
,
. (exporting data).
, ,
. (text files) / binary
.
(format)
, :
(Text data): ,
American Standard Code for
Information
Interchange
(ASCII),
ASCII
(text editor).
Binary data: binary ,
ASCII
.
binary ,
, . ,
American Standard Code for
- 72 -
MATLAB &
Information
Interchange
(ASCII),
. ASCII
(text editor).
, MATLAB
,
,
.
, MATLAB
(Import Wizard),
.
-
,
C (standard C-language file I/O function)
,
. ,
,
, script file
, .
5.1 Matlab
MATLAB ,
.
, , ,
.
( ),
,
(delimiter),
. ,
(,), (;) .
, , ,
,
.
binary data
, .
(, animations, ).
- 73 -
MATLAB &
,
text data
binary data.
delimiters
cvsread
dlmread
fscanf
(space)
load
(;)
textread
Binary
auread
.au
aviread
.avi
hdf
.hdf
imread
data
in
SUN
Microsystems format
audio-visual
data
in
AVI
format
data
in
Hierarchcal
Data
Format
image data in many formats
wavread
.wav
wk1read
.wk1
xlsread
.xls
sound
load
MATLAB
data
in
Mat-files
format
sound
data
in
Microsoft
Windows format
data
in
Lotus
123
spreadsheet format
data
in
Microsoft
Excel
spreadsheet format
MATLAB.
MATLAB load.
- 74 -
MATLAB &
, ,
.
, Mydata.txt,
:
12356
7 8 9 10 11
:
>> load Mydata.txt
>> Mydata
Matab
Mydata =
1
10
11
dlmread. (Mydata.txt),
(;) ,
dlmread:
>>A=dlmread('Mydata.txt',';')
A=
1
10
11
MATLAB textread. ,
, :
[A,B,C,]=textread(filename,format,,parameter,value,.)
filename x
format x
, , MATLAB.
,
.
N x ,
,
format.
- 75 -
MATLAB &
parameter value x
textread, .
MATLAB.
- 76 -
MATLAB &
.
: Mydata.txt
Grade1 Grade2 Grade3
78.8
55.9
45.9
99.8
66.9
78.2
89.8
77.0
56.3
,'%f %f %f','headerlines',1)
Grade1 =
78.8000
99.8000
89.8000
Grade2 =
55.9000
66.9000
77.0000
Grade3 =
45.9000
- 77 -
MATLAB &
78.2000
56.3000
: Mydata.txt
Aris
Kostas
Maria
Type2 34.60 30 No
Type3 10.89 50 Yes
>> [names,types,x,y,answer]=textread...
('Mydata.txt','%s %s %f %d %s',3)
names =
'Aris'
'Kostas'
'Maria'
types =
'Type1'
'Type2'
'Type3'
x=
12.5000
34.6000
10.8900
y=
40
30
50
answer =
'Yes'
'No'
'Yes'
,
(Current directory), MATLAB
directory, .
Import Wizard
MATLAB
,
, Import Wizard.
- 78 -
MATLAB &
Open,
Windows.
:
directory
(Open) .
Import
Wizard.
, .
(),
,
.
, Next.
,
(Workspace). ,
.
,
Finish.
, , .
- 79 -
MATLAB &
Import Wizard.
Mydata.txt. ,
Next.
Mydata.txt
MATLAB.
data. ,
Finish.
- 80 -
MATLAB &
(Command Window).
9: Command Window
Import Wizard
binary.
5.2 Matlab
MATLAB, ,
,
,
.
- (text
data)
binary
data.
,
.
text data binary data.
- 81 -
MATLAB &
delimiters
cvswrite
dlmwrite
fprintf
save
diary
(;)
(space)
Tabs
Binary
auwrite
.au
avifile
.avi
hdf
.hdf
imwrite
sound
data
in
SUN
Microsystems format
audio-visual
data
in
AVI
format
data
in
Hierarchcal
Data
Format
save
.mat
wk1write
.wk1
wavwrite
.wav
MATLAB
data
in
Mat-files
format
sound
data
in
Microsoft
Windows format
data
in
Lotus
123
spreadsheet format
,
MATLAB,
.
, ,
delimited ASCII ,
save dlmwrite.
, ,
,
()
.
- 82 -
MATLAB &
save,
:
123 56
7 8 9 10 11
Myexport.txt, :
Myexport.out,
:
,
dlmwrite,
(Myexport.out).
:
1;2;3;5;6 7;8;9;10;11
(delimiter), (,)
.
( ) ,
(quotes,) ,
.
,
MATLAB, diary.
:
>> diary Myexport.out
diary
A=
- 83 -
MATLAB &
10
11
diary
, ,
:
A=[1 2 3 5 6;7 8 9 10 11]
A=
1
10
11
diary off
,
.
- 84 -
MATLAB &
6 ,
,
2. Elter D.M. (1997), Engineering problems solving with MATLAB, Prentice
Hall
3. Etter D., Kuncicky D. and Moore H. (2004), Introduction to MATLAB 7,
Pearson Education Limited
4. Hanselman D.C and Littlefield B.L. (2004), Mastering MATLAB 7 A
comprehensive tutorial and Reference, Prentice Hall
5. The Mathworks, Inc. (2001), Using MATLAB 6
6. The Mathworks, Inc., MATLAB Documentation, v.6.5
7. Pratar R. (2006), Getting Started with MATLAB 7, Oxford University
Press, New York
8. Wilson H., Turcotte L. and Halpern D. (2003), Advanced Mathematics and
Mechanics Applications using MATLAB, Chapman & Hall/CRC
9. . (2006),
MATLAB,
...,
10. . (2004), MATLAB 6.5, ,
11. . (2007), MATLAB
7 , ,
- 85 -
MATLAB &
A.
, x :
; x :
: x :
if
x :
x :
. x :
... x :
- 86 -
MATLAB &
% x :
(sprintf, fprintf)
() x :
[] x :
- 87 -
MATLAB &
.
sin
asin
sinh
asinh
cos
acos
cosh
acosh
tan
atan
tanh
atanh
cot
acot
coth
acoth
sec
asec
sech
asech
csc
acsc
csch
acsch
exp
log
log10
sqrt
expm1
log1p
log2
nthroot
pow2
nextpow2
realpow
reallog
abs
angle
conj
complex
real
imag
unwrap
cplxpair
Bessel
bessely
besseh
beta
betain
betaln
ellipj
ellipke
erf
erfinv
gamma
gammainc
legendre
rat
dot
cross
- 88 -
MATLAB &
.
, ,
,
... 2003.
(script file) MATLAB, ,
,
, I/O functions
,
.
(script file),
.
...2003
, :
0
R d (T) = 1 +
1 , 0 <1
1
q
0
R d (T) =
,
1 2 ,
q
R d (T) =
0
q
2 <
: . 1.
: .
,
A=0.24g=2.3544 m/sec2
: 5%.
1.
: . 1.
: . 2.5.
q: . 3.0.
- 89 -
MATLAB &
,
,
, ...2003.
:
0.10
0.15
0.20
0.40
0.40
0.60
0.80
1.20
,
spectra.m. , ,
, (Command window) ,
(Current Directory),
, .
% SPECTRA - (script file) - ,
E.A.K. 2000
% To . 10/1/2008
% spectra.m :
% )
%
, ... 2003
% )
% )
%=======================================================
%
%=======================================================
%
%=======================================================
im=1;
a=2.3544;
% ,A=0.24g ( m/sec2)
h=1;
% 5%
theta=1;
bita=2.5;
q=3;
T1A=0.10;,T2A=0.40; %
T1B=0.15;,T2B=0.60; %
T1C=0.20;,T2C=0.80; %
T1D=0.20;,T2D=1.20; %
- 90 -
MATLAB &
%
%=======================================================
jA=0;
jB=0;
jC=0;
jD=0;
for T=0:0.01:4
if T<T1A
jA=jA+1;
Acc_A(jA)=im*a*(1+((T/T1A)*((h*theta*bita/q))-1)); %. . . , 0<=1
elseif T>=T1A & T<=T2A
jA=jA+1;
Acc_A(jA)=im*a*h*theta*bita/q; %. . . , >=1&<=2
elseif T>T2A
jA=jA+1;
Acc_A(jA)=im*a*(h*theta*bita/q)*((T2A/T)^(2/3)); %. . . , >2
end
if T<T1B
jB=jB+1;
Acc_B(jB)=im*a*(1+((T/T1B)*((h*theta*bita/q))-1)); %. . . , 0<=1
elseif T>=T1B & T<=T2B
jB=jB+1;
Acc_B(jB)=im*a*h*theta*bita/q; %. . . , >=1&<=2
elseif T>T2B
jB=jB+1;
Acc_B(jB)=im*a*(h*theta*bita/q)*((T2B/T)^(2/3)); %. . . , >2
end
if T<T1C
jC=jC+1;
Acc_C(jC)=im*a*(1+((T/T1C)*((h*theta*bita/q))-1));%. . . , 0<=1
elseif T>=T1C & T<=T2C
jC=jC+1;
Acc_C(jC)=im*a*h*theta*bita/q; %. . . , >=1&<=2
elseif T>T2C
jC=jC+1;
Acc_C(jC)=im*a*(h*theta*bita/q)*((T2C/T)^(2/3)); %. . . , >2
- 91 -
MATLAB &
end
if T<T1D
jD=jD+1;
Acc_D(jD)=im*a*(1+((T/T1D)*((h*theta*bita/q))-1));%. . . , 0<=1
elseif T>=T1D & T<=T2D
jD=jD+1;
Acc_D(jD)=im*a*h*theta*bita/q; %. . . , >=1&<=2
elseif T>T2D
jD=jD+1;
Acc_D(jD)=im*a*(h*theta*bita/q)*((T2D/T)^(2/3)); %. . . , >2
end
end
% .table
% H file I/0 function
%=======================================================
T=0:0.01:4;
z=[T;Acc_A;Acc_B;Acc_C;Acc_D];
fid=fopen('Notes.table','w');
fprintf(fid,' \n');
fprintf(fid,'=================================================
======================\n');
fprintf(fid,'
fprintf(fid,'
fprintf(fid,' sec
Rd(T)
Rd(T)
(m/sec2)
Rd(T)
Rd(T)
\n');
\n');
(m/sec2)
(m/sec2)
(m/sec2)
\n');
fprintf(fid,'=================================================
======================\n');
fprintf(fid,'%6.2f
%10.2f
%10.2f
%10.2f
%10.2f\n',z);
fclose(fid);
%=======================================================
subplot(2,2,1)
plot(T,Acc_A)
grid on
- 92 -
MATLAB &
ylabel('Rd(T) (m/sec2)','FontSize',9,'FontWeight','bold')
xlabel('T (sec)','FontSize',9,'FontWeight','bold')
subplot(2,2,4)
plot(T,Acc_D)
grid on
title('Spectral values - Soil D','Fontweight','bold')
ylabel('Rd(T) (m/sec2)','FontSize',9,'FontWeight','bold')
xlabel('T (sec)','FontSize',9,'FontWeight','bold')
,
, MATLAB.
- 93 -
MATLAB &
9:
- 94 -