You are on page 1of 388

1 MATLAB

MATLAB
Nachtigal, M. N., Reddy, S. C., Trefethen, L.N.(1990)

Copper Mountain
Copper Mountain CO, 1-5,19904

1.1 MATLAB
MATLAB

MATLAB

M AT L A B M AT L A B

MATLAB
MATLAB MATLAB F O RT R A N

25MATLAB
MATLAB





MATLAB MATLAB (MATrix LABoratory)

1.2 MATLAB
M AT L A B
MATLAB
M AT L A B
M AT L A B M AT L A B M AT L A B

MATLAB

MATLAB 5

command(parl, par2)par1 par2


1.1
MATLAB MATLAB

(a) MATLAB 0x6sin(2x)sinx2sin2x


x=linspace(0,6);
y 1 = sin(2* x);
y2=sin(x.^2);
y3=(sin(x)).^2;

%
%
%
%

x
y 1x xs i n ( 2 x )
y 2s i n ( x . ^ 2 )
y 3( s i n ( x ) ) . ^ 2

p l o t ( x , y 1 ) y 1y 1 x p l o t 1 3
sin(2x)sin(x2)sin2x (1-1)

1-1

(b) MATLAB1-2
f(x, y) = cos (x)sin (y)surfshading interp

meshwaterfallcontour13
surfshading interp

mesh

mesh

contour

1-2

1 MATLAB

(c) MATLAB

x-y 1-3

1-3

1.2
MATLABfzerofmin
2

xex e x sin x 3 f u n c (2 . 9)
func.mM

M matlab func
MATLAB xiszero=func(0)
xiszero =
1

MATLAB x ex2e x2 s i nx 3= 0
xsolv=fzero(func, 3)
xsolv =
1.2194

2 3
1x1.5 1-4

1-4 1x1.5 xex ex sinx3


2

MATLAB 5

x0 . 51
mpoint=fmin(func, 0 . 5 , 1
)
mpoint =
0.8954

MATLAB 1011

1.3
(a) MATLAB Ab

Ax=b

x=A\b

(b) (a)A

EigenVectorsA EigenValues A

MATLAB 3 47
89
1.4
(a) xyx-y

1 M AT L A B

x-y 9
MATLAB
p1=polyfit(x, y, 1)
linc=polyval(p1, x)
plot(x, linc,x, y
x)
,

% p 1 = A
% linc=Ax p 1
% x

1-5()
7

p7=polyfit(x, y, 7);
xx=1:0.25:8;
polc=polyval(p7, xx);
p l o t = ( x x , p o l c , x , x)
y,

%
%
%
%

p 7 = A7
x x =
polc=A
x xp 7
x

1-5()

1-5 x-y 9 17

(b) MATLAB (xiyi)xi ,MATLAB

(a)

1-6 piecewise () ()

MATLAB 5

xi=(1 1.1 1.2 1.3 7.9 8)


1 - 6x

10

1.5
MATLAB

1 - 7
9 2 111 2
77
3 2 3 2
35
11
11 x
6

200

1-7

1.6
MATLABFFT
MATLAB 01 5sin(x)+2sin(5x) :
x = l i n s p a c e ( 0 , *2
pi, 64);
signal=5* sin(x)+2* sin(5 * x)+randn(x);

1 MATLAB

1-8()

transf=fft(signal);
filttransf(1:9)=transf(1:9);
filttransf(56:64)=transf(56:64);

1 - 8 () 1 - 9 ()

filtsig=ifft(filttransf);

1-8

1-9

1 - 9 ()

1 0 . 5 M AT L A B
C

1.7
MATLAB
(x(t), y(t) )(X(t) ,Y(t) )
(5040)

w at

(t) = (X(t) x(t)) 2 + (Y(t) y(t))2


1-10

MATLAB 5

1-10

11.2 MATLAB

1.8
MATLAB P D E
(the Finite Element Method)

u=sin(2 y+ /2)cos(2 x+ /2)1-11


u=0PDE

1-12
PDE

1-11 PDE FEM

1-12 PDE

1.9 MATLAB
MATLAB MATLAB
.m M
M MATLAB
(a) n=123n

1 M AT L A B

function p =factorial(nn)
nn

Mfactorial.m
fourfactorial=factorial(4)

fourfactorial=
24

(b) MATLAB world

world @worldworld.m
Function w=world(Size, Density, nrCreate, nrSurvive)
% WORLD
%
% Size
% Densit
y 01
% n r C r e a t
e
% n r S u r v i v
e

@w o r l d

w
w=world(20, 0.6, [2 4 5], [3 6 7]);

w=year(w)

10 10
1-13
MATLAB12

1-13 10 w

1.10
MATLAB
14.3 14.4

10

MATLAB 5

1-14 MATLAB

1.3 MATLAB
MATLAB MATLAB
MATLAB
helpMATLAB
MATLAB5 HTML
h e l p d e s k Netscape Navigator
Microsoft Internet Explorer
MathWorksMATLAB

2 MATLAB
MATLAB
MATLAB
AMATLAB

2.1 MATLAB
MATLABWindows Macintosh
UNIX
matlab

M AT L A B m a t l a b rc . m

s t a rt u p . m
MATLAB c o n s t a n t s
matlabrc.m startup.m2.20(c)
MATLABquitexit
1
exitquit

M AT L A B
2.8

Ctrl-c

M AT L A B M AT L A B

Wi n d o w sM a c i n t o s h
quit
MATLAB

2
Ctrl_p

Ctrl_n

Ctrl_f

Ctrl_b

D e l e t e , B a c k s p a c e
Ctrl_l Ctrl_

Ctrl_r Ctrl_

12

MATLAB 5

Ctrl_a Home

Ctrl_e

Ctrl_k

cedit

help cedit

2.2 MATLAB
MATLAB
mnmn2mnp
2.1
23

1(1 2 3)2

aij aij i j
2 . 1a21= 4
(4) 5.5

11
MATLAB
v a r i a b l e =e x p r e s s i o n

expression
e x p r e s s i o n MATLAB a n s( a n s w e r
)
[](help paren)

MATLAB help punct


MATLAB

5.1.3

variable (rowIndex, columnIndex)

2.3

2 MATLAB

13

2.2
(a) x=7
x=
7

(b) 7
ans=
7

(c) 2 3
A=[1
4 5

2
3
6]

A=
1

2
4

3
5

(d)
A=[ 1

4
3

6]

(e)
rowvec=[1.2
3.2
4];
c o l v e c = [ 2 . 7 ; 3 . 4 9
; .2];

(f) colvecMATLAB
c o l vec=
2.7000
3.4000
9.2000

(g)
B ( 11)=1
B ( 12)=7
B ( 21)=5
B ( 22)=0

B=
1
5

7
0


2-1 332

r e s h a p e ( 3 7 )
2-2

14

MATLAB 5

2-1 332

2-2 332

2.3
(a) AB

C
C (1)=A
C (2)=B

(b) C
C ( 111)=100

M AT L A B

2.4
(a)
x = 7y = 4 . 6 7 3 5 5 6 7 ; z = x ^ y ;

(b)

MATLAB
sizelength

2 MATLAB

15

Amnpxm1( )1n(
)MATLAB
3
A

size(A)

[mnp]=

Amn

size(A)

dimA

size(Adim)

xx

size(x)

1m21
x112n
x

length(x)

n x
m
length(A)

mnp

ndims

A
length(size(A))

sub2ind(sizemn)

size(mn)

[mn] = i n d 2 s u b

ind (mn)

(sizeind)

s i z e

di m e m s i o n

sizelength
2.5
(a) thesize1=size(A)A2.2(c)
thesize1=
2

thesize2=size(C)C2.3
thesize2=
2

(b)2-2

16

MATLAB 5

2.3 MATLAB
MATLAB 1 9 AZaz _

clear
MATLAB aA MATLAB
abs(A)AABS(A)
MATLAB

4
double

64

char

16

sparse

sparse4+( *16)

unit8

512
MATLAB
repmat(4.1)
5
iscell(x)

x 10 5.5

isfield(x)

x1012.5

isfinite(x)

x x 1
0

islogical(x)

x 10

isnumeric(x)

x 10

isstr(x)

x 10 5.1

isstruct(x)

x 10 12.5

isobject(x)

x 10 12.6

logical(x)

2.6

2 MATLAB

17

repmatx

round

repmat 4.1

MATLAB
6 MATLAB
ans

eps

1 e p s
e p s
epsclear

realmax

realmin

pi

3 . 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3e p s 1 6

inf

1 / 0 MATLABi n f

NaN

Not a Number
inf/inf

18

MATLAB 5

ij

ij

clear
nargin

12.3

nargout

12.3

7
who

Who global

who 12.3

who a*
whos

a
who

whos global

whos 12.3

exist(namestr)

n a m e s t r
5

1) namestr
2) namestrM(2.9 )
3) namestrMEX(15)
4) namestrSIMULINK
5) namestr MATLAB

inmem

M
MEX

workspace

whosclear
help workspace UNIX

clear
8
clear

e p s
111 clear

clear name

name

c l e a r n a m e 1 n a m e 2 name1name2

clear a*
clear value

a
value
helpclear

2 MATLAB

19

MATLAB

pack

pack
pack.tmp

pack.tmp
pack.tmp
p a c k f i l e n a m e filename
helpclear

helpmemory

helppack

MATLAB

MATLAB

c l e a r name c l e a r (n a m e) w h o
g l o b a lw h o (g l o b a l) a x i s
s p u a r ea x i s (s q u a r e)13.3
/ MATLAB 5

2.4
MATLAB
3.141.23E6 1.23106
MATLAB
1) ^

2) *
/

()

\
3) +

1
()
3 . 3 2 / 50 . 45 \ 2

2.7
a
a
+ c a / ( b + c )
b +c
b
b +c
a\(b+c)MATLAB
a

a/b+cMATLAB

MATLAB

20

MATLAB 5

MATLAB
9 3.6

9
abs(x)

x |x|

sign(x)
sqrt(x)

x 1 10
x x

pow2(x, f)

x2 f f x

exp(x)

x ex

log(x)

x lnx

log10(x)

x10 log10x

log2(x)

x2 log2x

sin(x)

xx

cos(x)

xx

tan(x)

xx

cot(x)

x1/(tanx)x

asin(x)

sin1x

acos(x)

cos 1x

atan(x)

tan1x

atan2(x,y)

(x/y) [ ]

acot(x)

x=(1/x)

sec(x)

x1/(cosx)

csc(x)

x1/(sinx)

asec(x)

sec1x=arccos(1/x)

acsc(x)

csc1x=arcsin(1/x)

sinh(x)

cosh(x)

tanh(x)

coth(x)

x1/(tanhx)

asinh(x)

sinh 1x=ln (x + 1 + x 2 )

acosh(x)

cosh 1x= ln (x + 1 x 2 )

atanh(x)

tanh1x=0.5ln((1+x)/(1x))

acoth(x)

coth1x=0.5ln((x+1)/(x1))

sech(x)

x1/(coshx)

csch(x)

x1/(sinhx)

asech(x)

sech1x=ln ((1+ 1 x 2 ) / x)

acsch(x)

csch1x= ln ((1+ 1 + x 2 )/ x)

2 MATLAB

21

2.8
(a) sinepi=sin(pi)
sinepi=
1.22466e16

0pi

MATLAB 10x

10
round(x)

xx

fix(x)

0xx
x

floor(x)

ceil(x)

rem(x, y)

x/y

gcd(x, y)

xy

[ g , c , d ] = g c d (y
x ) gcdg=xc+yd
lcm(xy)

xy

[tn]=rat(x)

t/nx tn
106 rats(5.1.2)

[tn]=rat(xtol)

tol

rat(x)

rat(xtol)

tolx

2.9
(a)

22

MATLAB 5

(b)t/n 2

differ=sqrt(2)t/n
differ=
3.6440e-07

r a tt o l

MATLABij 1
ij
i i = sqrt(1)

2.10(c)
2.10

(b)
w = r* exp(i * theta)c o m p = z * w

rtheta
(c)
2 2i

c o m plexvector=[1i

3 3i ]

complexvector=
1 . 00001 . 0 0 0 0 i

2 . 0 0 02
0 .0000i

3 . 0 0 0 0 3
0 .0000i

33 i MATLAB

length(complexvector)

ans=
4

2 MATLAB

23

MATLAB
11
real(z)

imag(z)

abs(z)

z |z|

conj(z)

z z

angle(z)

z z=x+iy=rei

unwrap(v)

u n w r a p ( v , k ) k
cplxpair(v)

v v

2.11
z
z=1+2i

(a) z

(b) conjugate=conj(z)
conjugate=
1.00002.0000 i

z absz=abs(z)
absz=
2.2361

(c) arg=angle(z)
arg=
1.1071

M AT L A B

12
[theta, r]
=
cart2pol(x, y)

thetarx
y

24

MATLAB 5

[xy]=pol2cart

xy

(theta, r)

thetar

[alphathetar]=

alphathetar

c a r t 2 s p h ( x , y , z ) xyz
[x, y, z]=

xyz

sph2cart(alpha,theta,r)
MATLAB
13
legendre(nx)

n+1nlegendre
x0n x=x
x
Legendrex[
11]

bessel(n, x)

1 nx n
1[01000] x

help bessel

bessely(n, x)

bessel 2

gamma(x)

gammainc(xa)

gammaln(x)

log(gamma(x))

xh e l p g a m m
a

beta(xy)

x [ 01 ]
betainc
betainc(xab)

betaln(xy)

expint(x)

2 MATLAB

25

erf(x)

erfinv(y)

erfc(x)

1erf(x)

erfcx(x)

h e l p e r f c x

[ke]=ellipke(m)

120<m<1

[j1j2j3]=ellipj(xm)Jacobi
2.9 10.4

2.5

(flop) f l o p sMATLAB
12.7
14
flops

0 M AT L A B

1
2 1
6
1

flops(0)

2.12

numflops=
4

MATLAB f l o p s

15 ()
tic

toc

toc

toc0

26

MATLAB 5

clock

6 5
f i x ( c l o c k )

etime(t1, t2) t 1t 2 t 1t 2
6
cputime

MATLAB CPU

2.13

t1=clock

MATLAB
t i m e d i f f e r e n c e = e t i m e ( t 1 , c l oc k )

MATLAB

16 ()
date

calendar(yyyymm)

yyyymm 67

datenum(yyyymmdd)

yyyymmdd
000001011

datestr(dform)

f o r m
2-1

datetick(axis, form)

datevec(d)

d d a t e s t r
[y y y y
mm dd ho mise]

eomday(yyyymm)

now

[daynr dayname]=

dayname day

weekday(day)

d a y n r d a y
d a y

d a t e s t r 2-11986426214

2 MATLAB

27

2-1
0

dd mmm yyyy HH:MM:SS

26 Apr 1986 02:14:00

dd mmm yyyy

26 Apr 1986

mm/dd/yy

04/26/86

mmm

Apr

m#

mm/dd

04/26

dd

26

ddd

Sat

10

yyyy

1986

11

yy

86

12

mmmyy

Apr86

13

HH:MM:SS

02:14:00

14

HH:MM:SS PM

2:14:00 AM

15

HH:MM

02:14

16

HH:MM PM

2:14 AM

17

QQ-YYQQ

Q2 86

18

QQ

Q2

2.14

MATLAB 7

2.6

M AT L A B
MATLAB16
f o r m a t Wi n d o w sM a c i n t o s h

28

MATLAB 5

17
f o r m a t d e f f o r m a t defformat
shortlongs h o r t l
e ong e
hex
+b a n kr o t c o m p a c tl o o s e

f o r m a t c o m p a c
t

more on

M AT L A B m o re

more off

more(n)

n n

2.15
p=1+1/3 p
format
format
format
format
format
format

short
long
short e
long e
hex
+

1.3333
1.33333333333333
1.3333e+00
1.333333333333333e+00
3ff5555555555555
+

1.33
4/3

format bank
format rat

4
1 4
4
1 5
1 6
+
0

MATLAB
f o r m a t c o m p a c
t

2.7

18
help

2 0
h e l p d i
r
dir

h e l p c o m m a n d
help dir

dir

hthelp

M AT L A B G U I

htpp

hthelp

loadhtml

hthelphttp HTML

helpdesk

2 MATLAB

29

helpdesk

MATLAB Web

doc command

MATLAB command

web URL

U R L h e l p
web

l o o k f o r t e x t M1 text
demo

M AT L A B
demoMATLAB Expo

expo

MATLAB Expo demo

info

MATLAB
M AT L A B MATLAB

whatsnew

subscribe

MATLAB

why

M ATLAB Help Desk H T M L h e l p


l o o k f o r
M ATLAB Help DeskJava Script Java Script
h e l p d e s k 2 - 3 MATLAB
Jave Script UNIX docopt.mM
WindowsMATLAB.htm
2.16
(a) h e l p s i z
e
S I Z E
D=S I Z E(X)MNX D= [MN] NDSIZE(X)1N
[ MN ]=S I Z E(X) [ M 1M 2M 3 M N ]=S I Z E(X)XN

M=S IZE(XDIM) D I M S I Z E ( X1 )
LENGTHND I M S

MATLAB
(b) MATLAB Help DeskhelpdeskMATLAB2-3
( )

30

MATLAB 5

2-3 MATLAB Help Desk

(c) l o o k f o r s i n
e
ACOS
ACOSH
ASIN
ASINH
COS
COSH
SIN
SINH
TFFUNC
DST
IDST

MATLAB d e m o h e l p

MATLAB MATLAB
19
[str, n]=

MATLAB str

computer

VA XS u nP CM a c i n t o s hn
MATLAB

isieee

I E E E 1 I B M P CM a c i n t o s h
IEEE 0VAXCray

2 MATLAB

version

MATLAB

31

ver

MATLAB

hostid

MATLAB

getenv(str)

strstr

terminal

MATLAB

2.17
SunSolaris 2
[comp, numb]=computer

2.8
MATLAB d i a r y
13.7
20
d i a r y f i l e n a m
e filename
diary off

diary on

diary

diary

ASCII d i a r y
MATLAB
s a v el o a d
f i l e n a m e M AT L A B . m a t
filename.ASCII
21
save

matlab.mat

save filename

f i l e n a m e . m a t
f i l e n a m e.
MATLAB .mat

s a v e f i l e n a m e v 1 v
2

filename.mat v1v2

32

MATLAB 5

s a v e f i l e n a m e v - a s c if
i
ilename.matASCII
v8
s a v e f i l e n a m e V - a s c if
i
ilename.mat ASCII16
-double

load

filename.mat

load filename

f i l e n a m e . m a t M AT L A B
f i l e n a m e s a v e

-mat
f i l e n a m e . t e m p . d a t
A S C I I M AT L A B
. f i l e n a m e
save file var-ascii

2.18
ASCIIA.dat
1 4 5
4 2 9
MATLAB

5 . 8 ( b )
1515 FORTRANC

2.9
MATLABMATLAB

MATLABMATLAB
MATLAB MATLAB
matlabpath 22
run12
M
filename.m

.m
M MATLAB M

33

2 MATLAB

MATLAButility-disk Mcond.m demo.m


l e n g t h . mh i l b . m w h a t
MATLABM
dirwhat MATLAB
22
what dirname

M AT L A B
dirnamedirname

dir

ls

pwd

delete filename

filename

cd

type filename

f i l e n a m e
MATLABfilename.m

edit file

f i l e

copyfile (file1,

file1file2help copyfile

file2)
which filename

filename

path

MATLAB
help path

matlabpath

genpath(directory)

MATLABROOT/toolboxdirectory
directory

pathsep

matlabpath

partialpath

editpath

MATLAB

a d d p a t h ( d i r 1 , d i r 2 , MATLABdir1dir2
, flag)

f l a g

rmpath dir

MATLAB dir

pathtool

help

34

MATLAB 5

p a t h t o o l U N I X
UNIX

path2rc

p a t h d e f . m
MATLAB

dbtype filename

f i l e n a m e f i l e n a m e
MATLAB.m

d b t y p e f i l e n a m e r 1 : rf
n
ilenamer1rn
lasterr

lastwarn

M a c i n t o s h

isstudent

M AT L A B (Prentice Hall
)1 0

isdir dirname

dirname 1 0

isppc

Macintosh Power PC M AT L A B
1 0

isunix

UNIXMATLAB10

isvms

VMSMATLAB1 0

vms

MATLABVMS DCL
h e l p vms
VMS

dos

MATLAB DOS
h e l p d o s
PC

applescript

Apple Script h e l p d e s k

unix

MATLABUNIX

Macintosh
help unix

tempdir

tempname

t p MATLAB

matlabroot

MATLAB

m a t l a b M MATLAB

2.19
(a) MATLABsec.m

2 MATLAB

35

type sec
f u n ction y=sec(z )
% SEC
%
S E C ( X )X

M MATLAB
Xz./3.5
(b) h e l p s e c
sec.m
S E C
SEC(X) X

M
M ;
s e c z ( )
script h e l p s c r i p
t
MATLAB C FORTRAN
f u n c t i o n
M
() () MATLAB

function output = name(input)

0
FORTRANPascal C/C++
function = name(inputArguments)

MATLABM
filename(inputArguments)

help name

MATLAB (

M A S C I I
MATLAB M
22
2.20
(a) 2.8
M MATLAB T h e m a t r i x . m

A = [9

3 - 1 61 3

1
6 3

1 0
]

36

MATLAB 5

T h e m a t r i xA

(b) average.m
function y=average(A)
A
[m, n]=size(A);
y=sum(sum(A))/m/n;

(a)
average_value = average(A)

average_value =
2.6667

average
function y=average(A)
A
y=mean(A(:));

6summean4.3 A(:)
(c) s t a rt u p . m M AT L A B
MATLAB
MATLABMATLAB
% startu p . m
d i s p(W e l c o m e t o M A T L A )
B!

MATLAB

M 12.3

3
MATLAB 2 . 4 +
*^/\
MATLAB 16384

3.1
AB A+B AB
ABaijpbijpMATLABmnA 11
s A+sA aij+s
3.1
AB

MATLAB
A d d = A + B , S u b =B
A , Add100=A+100

3.2
ABC=AB
MATLAB11
MATLABMATLAB*C=A*B
c ijAiBj 2 3 B C
A B

38

MATLAB 5

BA AB
3.2
(a) AB3.1
A , B , M u l t A B =*A
B,

M u l t B A =*BA

(b) xy

s=x*y M=y *x

MATLAB d o t ( xy ) xy
AB
ABMATLAB
12 B
23
dot(x, y)

xy

dot(A, B)

nAB
ABmnhelpdesk

d o t ( A , B , d i m )dim AB

39

xyc r o s s ( x , y
)
xyxy
cross 3n 3n iAB
i
24
cross(x, y)

xy

cross(A, B)

3n AB
AB 3n

c r o s s ( A , B , d i m ) d i m AB AB
s i z e ( A , d i ms
) i z e ( B , d i m3
)
3.3

x=(1 0 0)

y=(0 1 0)

c r o s s p r o d = c r o s s ( x ,
y)
crossprod=
0

xy
scalar1=dot(x,crossprod), scalar2=dot(y,crossprod)

MATLAB F I R( )
helpdesk
25
conv2(A, B)

AB

c o n v 2 ( h c o l , h r o w , A ) Ahcolh ro w
conv2(,format)

f o r m a t

sameA
valid

convn(A, B)

AB

convn(, format)

40

MATLAB 5

K r o n e c k e r kron(A, B) A mn
Bkr mkrn
26
kron(A,B)

ABKronecker

3.4

K = k r o n ( A , B
)

3.3
MATLAB \/A
A \ BB / AAB i n v ( A ) *BB* i n v ( A )
MATLAB 3.5Ainv(A)A17.1
A X = A \ B A X=BA1B X B
B=b x=A\b AX=b7.2
Am>nmnX=A\BAX=B 7.7
X A=BX=B / A ( A\ B),
3.4
3.5
(a) AB3.1
ABR i g h t = B / A , L e f t = A
\B

41

Right=B*inv(A)Left=inv(A) *B

/\
(b) Ab

Ax=bMATLABx=A\b

(c) Ab,Ax=b
flops(0);x=in v ( A )* b ; f l o p s

ans=
109
f l o p s ( 0 ) ; X = A \ b ; f l o
ps
ans=
72

M AT L A B
flops2.5

3.4
MATLAB
*H
A 1 122
mnnm
Aaij A(i, j) a ji
.A. conj(A)
AAA.
3.6
Ab3.5(b)
T r a nsp=A,Transpb = b ,

42

MATLAB 5

3.5

+
.*
./
.\
.^

.
3 . 4
3.7

(a) A. *B

(b) B./A

(c) B.^2

(d) A.^B

(e) 2.^[1 2 3 4]
ans=
2

16

(f) C.

43

13.1

3.6
MATLAB (2 . 4) f
A a ij f(A) ij=f(a ij)

3.8
ABC

(a) abs(A)

(b) cos(B)

(c) sin(abs(C))

M AT L A B
M 2.9
3.9
s i n c o s (x) = s i n (x) c o s (x) M AT L A B
sincossincos.m
function y=sincos(x)
y = s i n ( x ) .*c o s ( x ) ;

sincos:

44

MATLAB 5

0y 1 e p s
s i n c o s s i nc o s

M 1213

3.7
Ap A ^p p
p= 0 A p< 0 A - 1
A^pinv(A)^(-p)
exp(A)sqrt(A)MATLAB (3.6) A

MATLAB A1/2(A)eA

27

Pade eA
M eA
eA
eA
A
A1/2A
f c n A 5 . 1 . 4
f c n s i nc o s
2.4 expm(A)=funm(A,exp)
[ F , E ] = f u n m ( A , f c nFE
)
polyvalm(p,A)
A p
10.1

expm(A)
expm1(A)
expm2(A)
expm3(A)
logm(A)
sqrtm(A)
funm(A, fcn)

expmexplogmlog
3.10

expexpm
Elementwise=exp(A), Operatorwise=expm(A)

45

3.8
MATLAB

<

<=

>

>=

==

~=

10
1

3.11
(a) pi ratpi
[t, n]=rat(pi), piapprox=t/n;
format long, piapprox, pi, piapprox==pi

(b)

A B

46

MATLAB 5

Greater=A>B

A(13)(32)B
(c) A(b)A 1
GreaterThanOne=A>1

3.9
MATLAB
&

xor

x o ro r o r x o r

&|

10
28
A&B

AB AB
1 0

A|B

AB AB
1 0

AB A
1A 0

xor(A, B)

AB AB
0AB
1

47

3.10
MATLAB Amn x

MATLABfind
29
x

find(x)

[ ]
A

find(A)

[ u , v ] = f i n d ( A ) uv A A
(uk, vk)
[u,v,b]=find(A)

A uv
A(uk, vk) bk

3.12
xA

(a) i n d = f i n d ( x ) , i n d c o l = f i n d:
(A)

x124 indcol
find(y)

(b) find
index=find(x>0.5)
index=
1

greaterThan=x(index),
greaterThan=
3.0000
6.1000

indexx 0.5
x 0 . 5 l e n g t h ( f i n d ( x > 0 . 5 )
)

48

MATLAB 5

ans=
2

(c) A
[index1, index2]=find(A)

(11)(22)

MATLABa n ya l l 0
1 if 12.1
30 ()
any(x)

x 10

any(A)

A 10

all(x)

10

all(A)

A 10

a n y ( a n y ( A ) )a l l ( a l l ( A ) )
10
3.13
(a) a l l ( x < = 5 )1 x 5 0
5all(all(A<=5))1A 5
(b) Aall(all(A==A))1A
(c) a n y ( a n y ( t r i l ( A ,1 ) ) )0 A A
a l l ( a l l ( A = = t r i u ( A ) ) ) A
1

31 ()
isnan(A)

A A
NaN10

isinf(A)

49

A A
inf10

isempty(A)

A 1 0

isequal(A, B)

AB
1

isreal(A)

A 1

isfinite(A)

A A
1

4
2 . 2

4.1
1ones10zeros
0 1 0
eyen 1
32 1

ones(m,n,... ,p)

nn1
mn... p1

ones(size(A))

A 1

zeros(n)
z e r o s ( m , n , . . ., p )

nn0
mn ... p0

zeros(size(A))

A 0

ones(n)

eye(n)

nn eye

eye(m, n)

mneye

eye(size(A))

4.1

51

r a n d 0
1 MATLABr a n d n

33
rand

01

rand + i*rand

rand(n)
nn 01
rand(m,n,... ,p) mn. . . p 01

rand

nn
.
.
.
randn(m,n,
,p) mn . . .p

randn(n)

M ATLAB 5
[ 2 5 3, 1 2 5 3]

2 1 4 9 2 1 0 4 4 9

MATLAB 4
34
rand(state)

35

rand(state,s)

52

MATLAB 5

rand(state,0)

rand(state, j)

jj

rand(state,

clock(15)

s u m ( 1 0 0* c l o c k ) )

rand(seed,arg)

MATLAB 4

randn(state)

randn(state,arg) arg rand


4.2
(a) ( 3 5)

( b ) MATLAB
clock

clock 2.5

MATLAB Amnx
n 35diag
35 ()
diag(A)

diag(x)

53

n x
0

diag(A,k)

Ak k= 0
k<0kk>0k

diag(x,k)

(n+ a b s (k) )(n+ a b s (k) ) k


x k

4.3

(a) diag_element=diag(A)

(b) Diag_matrix=diag(diag(A))

(c) Dmatrixx=diag(x)Dmatrixx=diag(x)

(d) superDiagElement=diag(A,2)
superDiagElement =
3
8

(e) NewMatrix=diag(diag(A,2))
NewMatrix =
3
0
0
8

diag(A, 2)

(f) S u p e r D i a g o n a l M a t r i x = d i a g ( d i a g ( A , 2
),2)

54

MATLAB 5

A2 2 44

MATLAB triutril
36 ()
triu(A)

A
A

triu(A,k)

A
k

tril(A)

A
triu(A,0)triu(A)
A
tril(A,k)

A k
A k
tril(A,0) tril(A)

A
A=triu(A) + tril(A) - diag(diag(A))

Atriu(A,1) Atril(A,
1)A
A = t r i u ( A , 1 ) + t r i l ( A1
, ) + diag(diag(A))

(Gauss-Seidel, Jacobi Successive Over


Relaxation(SOR))
4.4

(a) U p p e r T r i a n g u l a r = t r i u (

B)

(b) L o w e r T r i a n g u l a r = t r i l (
1
B ,)

55

37
fliplr(A)

Abij=ai,n-j+1
lrleft-right

flipud(A)

Abij =am-i+1,j
udup-down

flipdim(A, dim)

d i m A
flipdim(A, 1) flipud(A)flipdim(A, 2)
fliplr(A)

rot90(A)

A90
A
13.5

rot90(A, k)

Ak90
13.5

reshape(A,m,n,
. . .p )

mn...p
(2 - 2 ) A A mn . . .
p

repmat(A,[m n
. . .p ] )

Amn...p

repmat(x,[m n
. . .p ] )

mn...px
x *o n e s ( [ m n . . . ] )

shiftdim(A,n)

nnn

squeeze(A)

cat(dim,A,B)

AB dim

permute(A,order)

order A

ipermute(A,order)

permuteipermute(permute(A,
order), order) A

4.5
(a) 4 . 1 O n e M a t r i x B = r e s h a p e ( O n e M a t r i 3,
x,
8)

(b) B C = z e r o s ( 3 , 8 )

56

MATLAB 5

(c) Dcat(3,C,B)

(d) permuteshiftdim

MATLAB MATLAB

2.24.3

4.6

(a) x14
xnew=(9

10

5)

57

(b) A z

A y
Anew3=[A

y ]

Anew3=[A [11; 12]]

ABvert=[A; B]

ABhoriz=[A B]

A B v e rt AB A B h o r i z
AB

repmat

58

MATLAB 5

4.7
(a) r e p m a t ( [ 1 0 ; 0 1 ] , 3 ,
3)

(b) 3.2 r e p m a t ( [ 1 0 ] , 1 ,
5)

(c) r e p m a t ( 4 2 , [ 22])

4.2
MATLAB A = [ ]
010 31isempty
4.8
1-2-0-0-2 zeros(1,2,0,0,2)

zeros

59

whos

38E
squeeze
38
squeeze(A)

sum(E)

prod(E)

max(E)

min(E)

4.3
MATLAB :

39 ()
i:k

i 1k i ,i+1, i+2, . . . , k
i>kM AT L A B [ ] ik
k

i:j:k

i 1k i, i+j, i+ 2j, . . ., k
j= 0 ijk
k

4.9
(a) vect=2:7vect=2:7.7MATLAB

60

MATLAB 5

(b) vect2=6:1:1

(c) realVect=1.2:0.8:3.2

2.8
(d) realVect2=0:pi/4:pi

(e)
Mat1=[2:4 0.1:1:2.1; 1:6]

(f) sine

40 ()
linspace(a,b)

[a, b] 1 0 0 1 0 0

linspace(a,b,n)

[a, b] n

logspace(a,b)

61

[10a,10b]5050
b=pi
[10a, ]

logspace(a,b,n)

[10a,10b] n n

C / D D C C
C 41

e n d A432
A(end,2,1) a421A(end,end,end)a432
A 41
41
A ( i , j , . . ., k )

A(i, j, ..., k)2.3

A(:,j)

Aj

A(i,:)

Ai

A(:,j:k)

Ajj+1k

A(i:k,:)

Aii+1k

A(i:k,j:l)

A i k jl

A ( : , : , . . ., : )

A(:)

A(j:k)

A(:)jk
A(:)j1j2...

A([j1 j2 ... ])
. . .] )
A(:,[j1 j2

Aj1j2

A([i1 i2 ... ]:,) Ai1i2


A([i1 i2... ],
i1i2j1j2
.
.
.
[j1 j2
])
help colon

4.10
Ftable4.8(f)
(a) Submatrix=Ftable(2:4,:)

Ftable24

62

MATLAB 5

(b) ijk333
A ( e nd2 : e n d , e n2
d : e n d , e n2:
d
end )

(c) 3.8
Ftable20
Selected=Ftable(Ftable(:, 2) >0 ,: )

help list

4.4 MATLAB
4.1 1

MATLAB(Hilbert)H
hij=1/(i+j1)7.6
42
hilb(n)

nn

invhilb(n)

nn

4.11
H=hilb(3)Hinv=invhilb(3)MATLAB

( To e p l i t z )

43
toeplitz(k,r) k1r1

63

toeplitz(c) c
4.12
x = [ 1 2 3 4y
] = [ 9 8 7 6
]

gallery h e l p g a l l e r
y
h e l p p r i v a t e / f a m i
ly

44MATLAB
44
compan(p)

p pp
10.1

gallery(n)

nn n= 3
n= 5 n= 3 n= 5

g a l l e r y f a m i l y family 4-1
hadamard(k)

n= 2 k H a d a m a r d n4
Hadamard

hankel(x)

xHankel
hij=x i+j-a1x 0

hankel(x,y)

mnHankel1xy

magic(n)

nn

pascal(n)

nnP a s c a l
Pascal

64

MATLAB 5

pascal(n, k)

k=1 Cholesky Pascal


M AT L A B C h o l e s k y
k=2pascal(n,1)

rosser

Rosser,
88

vander(x)

2 xVa n d e r m o n d e
vi,j=xin-jnx

wilkinson(n)

mnWilkinson

4.13
mn 1n2
33 magic(3)

4.14
Householder help p r i v a t e / h o u s
e
HouseholderH

4-1 gallery
4-1 gallery
circul

dorr

house

Householder

invhess

Hessenberg

jordblock

Jordan

poisson

Poisson

vander

Vandermonde

wilk

Wilkinson

5
MATLAB

MATLAB

5.1

ASCII
ASCII

5.1.1
MATLAB
N a m eOfVariable=t e x t

t e x
t
5.1
(a) name=J o h n S m i th

(b) John Smith


ans

(c) (a)name name(3)=a

(d) name

eman

66

MATLAB 5

for-loops12.2eman=fliplr(name)4.1
(e) namelen=size(name)

(f)
whoscat='Joan"s cat'

w h o scat=
Joan's cat

(g)

47strcatstrvcat
(h)
n a m e = ' C h a r l e s J o h n s of
n ' i r s t n a m e = n a m e ( 1 : 7
)
firstname=
Charles

(i) text1=Johntext2=Joanc o u p l e = [ t e x t 1 ; t e x t
2]

5.1.2

45
abs(str)

strASCII

char(x)

x
a b s MATLAB
setstr

num2str(f)

disp

x l a b e l 1 3 . 3
13.9
num2str(f,k)

f k

num2str(f,format)

fformat format

67

sprintf
int2str(n)

rats(x,strlen)

x x
strlen 13

hex2num(hstr)

hstr
(IEEE)

hex2dec(hstr)

hstr

dec2hex(n)

base2dec(str,base)

strbase

dec2base(n,base)

n base

bin2dec(str)

dec2bin(n)

mat2str(A,n)

A n

str2num(str)

s t r
10e i

str2rng(str)

s t r [R1 C1 R2 C2 ]
s t r

strjust(str)

str

sprintf(formatstr,A)

A
formatstrC
fprintf
15.4

[Str,E]=

E E

sprintf(......)

sscanf(str,

formatstrstr

formatstr,mn)

mn
f s c a n f

15.4

[A, nm, E, next]=

sscanfA

sscanf(str,

mn E

formatstr,mn)

n e x t

5.2
str=ABCfloat=1.25

68

MATLAB 5

(a) x=abs(str)

ABCASCII
(b) number=hex2dec(str)MATLAB

(c)

n u m s t r

char=numstr(4)

MATLAB
char=
5

ischar(numstr)whos numstr
(d) numinfo=sprintf(T h e n u m b e r5
= .2e, f l o a t )

(e) rational=rats(0.979796)0.979796

littleRat=rats(0.979796,5)55

rat2.4
5.3
A

mat2str(A)

x=4.12345mat2str(A)

69

46str
46 ()
blanks(n)

deblank(str)

str

lower(str)

str

upper(str)

str

ischar(s)

s 1 0

isletter(str(i))

stri 1

isspace(str)

s t r s t r

10

strcmp(str1,str2)

str1str2 1 0

stricmp(str1,str2)

s t rc m p

str2mat(str1,str2,...)

str1str2stri
MATLAB
11

findstr(str1,str2)

str1str2

strrep(str1,str2,str3)

str1str2str3

strtok(str1,str2)

s t r 1s t r 2 s t r 1
s t r 2 M AT L A B
str1

[outstr,rstr]=strtok

o u t s t rs t r t o k ( s t r 1 , s t r 2 )
rstr

(str1,str2)

str1

lasterr

lastwarn

5.4
(a) name=upper(matlab)

70

MATLAB 5

name=
MATLAB

(b) fun=strrep(hahaha,a,i)
fun=
hihihi

(c)

str2mat(greet,where,party)

(d) strtok text

reststrtok
[day2,rest]=strtok(rest,,)

2 1

s t r c a t s t r v c a t
strmatchstrcmp
47 ()

strcat(str1,str2,

str1str2

...)

cat

strvcat(str1,str2,

str1str2 str1str2

...)

strmatch(key,strs)

strs
key

strncmp(str1,str2,n)

71

str1str2n1; 0

strncmpi(str1,str2,n) strncmp
5.5
(a) A5.3

s t r c a t
cat
(b)

tab

Table whos

5.6

72

MATLAB 5

cat

5.1.3
2 . 3

d i s p

48
disp(A)

AA

i n p u t A . 6
13.9dispnum2strint2str
49
input(out,in) out
ins
MATLAB
\nout
5.7
(a) x
x=input('Give a number x:')

(b) Ainput
A=input('Give the matrix A row by row:');

Give the matrix A row by row: [1

(c)

2 ; 3

5]

73

A=input('Please give me a matrix: ');

P l e a s e g i v e m e a m a t r:i xr a n d ( 4 *
)h i l b ( 4 )

(d)
[m, n]=input('Give the size of A:')

G i v e t h e s i z e o f :A s i z e ( A )

(e)

(f)
name=input('What is your last name? ');

W h a t i s y o u r l a s t n a?m e' S m i t h '


strname=input('What is your last name? ', 's');

W h a t i s y o u r l a s t n a?m e Smith

MATLAB 14.3
5.1.4
MATLABeval
50
eval(str)

strMATLAB

eval(str1, str2)

str1MATLAB
eval(str1)
str1
str2

[x1,x2,...]=evalin
(aa, str)

eval/
s t r a a c a l l e r (e v a l i n
)b a s e (MATLAB
) x1x2, ...

e v a l i n ( a a , s t r , a l ta
)
a() str
alt
a s s i g n i n ( a a , n a m e , valname

74

MATLAB 5

val)
g=inline(str,arg1,
arg2,...)

aa evalin
str g
g (v a l 1 ,v a l 2 . . .)
a r g1a r g2 . . .
M AT L A B s t r

g=inline(str,n)

n+1xP1P2...Pn

argnames(g)

vectorize(g)

* /^ .
g

formula(g)

char(g)

formula(g)

e v a lMATLAB MATLAB
12.4
5.8
(a) AB

5 . 1 . 3 d i s pi n p u t
switch-case12.1
A B
2 e v a l

75

eval catchInfo.m catchInfo

lasterrMATLAB

(b) file=myfile.mat
e v a l [s a v e, f i l e ] s a v e
myfile.mat2.8 save
(c) MATLABstr1=b.*sin(k.*x)bkx

values=eval(str1)

(d)
f c n = ' i n p u t ( ' ' G i v e a f u n c t i o n " , "
s")'

5.1.3 input
fplot(eval(fcn), [0,4])

Give a function

sinMATLAB
sinx2.mM(2.9)

M 1 2 . 3 Give a function s i n x 2

76

MATLAB 5

sinx2 5-1

5-1 sinx2[04]

MATLAB ifwhilefor12
5.9
3sin(x)+5cos(y)

whos

5.2
MATLAB 51ab

77

51
mod(a,b)

ab

factor(a)

primes(a)

isprimes(a)

a 1

nextpow2(a)

n 2n>a

perms(c)

nchoosek(A,k)

k Ak

permsnchoosek
5.10
4567 isprime(4567)
ans=
1

4569 factor(4569)

5.3
MATLAB 1 0
52
bitand(a,b)

ab

bitor(a,b)

ab

bitxor(a,b)

ab

bitget(a,bit)

abit

bitset(a,bit,newbit) newbitabit
bitshift(a,n)

an n

bitcmp(a,n)

na

bitmax

5.11
a=7, b=3, c=4: a=111, b=011, c=100bitand(a,b)

78

MATLAB 5

5.4
M ATLAB 5 5 3
ab rows

53
ab
a 0 - 1 a s
10
a b
a b b
a
ab
a

intersect(a,b)
ismember(a,s)
setdiff(a,b)
setxor(a,b)
union(a,b)
unique(a)
5.12
a = [ 1 2

24

42

24

1b
2 ]= [ 9 6

42

64]

union(a,b)

5.5
( ) ()

79

1{ } [ ]
2 3

5.13

24

catstrcat
54
cell(m,n)

mn

cell2struct(cell,

cell posts dim

posts,dim)

d i m= 1 c e l l 1
1 dim2

80

MATLAB 5

celldisp(cell)

cell cell

cellplot(cell)

cell

cellstr(s)

s
char

iscellstr(cell)

c e l l 1 c e l l
0

num2cell(A,dim)

A
dim dim
A

[out1,out2,... ]=
deal(in1,in2,...)

out1=in1out2=in2
helpdesk

5.14
5.13 B
cellplot(B)

5-2

5-2

81

celldisp(B)

6
MATLAB
ABmn...px

6.1
55
55
max(x)

xxmax(abs(x))

max(A)

A 1 1n . . . p
1 A 1

[y,ind]=max(A)

A max(abs(A))
A1 1n. . . py
ind

max(A,B)

AB AB

C=max(A,[],dim)

d i mA m a x ( A , [ ] , 1 )
A

min(x)

x max
x min(abs(x))

6.1
A

max(A)

83

whosA

6.2
sumcumsum
56
sum(x)

sum(A)

A 1n...p

cumsum(x)

x 2 x

cumsum(A)

A A

cumsum(A,dim)

A d i m

c u m s u m ( A )

cumsum(A,1)
6.2
6.1A

6-1MATLABsum(A)132TheSum

84

MATLAB 5

6-1 sum(A)

57

prod(x)

prod(A)

prod(A,dim)

dim

cumprod(x)

x 2 x

cumprod(A)

cumprod(A, dim)

dim

6.3
6.1A

diff diff
58
diff(x)

n1nx

85

x=(x1 x2 ... xn)diff(x)=(x2x1 x3x2...xnxn1)


diff(A)

A
diff(A)=A(2:m,:)A(1:m1,:)

diff(x,k)

kdiff(x,2)diff(diff(x))

diff(A,k,dim)

dim k

[DAdx,DAdy,
D A d z , . . .] =

DAdxDAdy DAdzA

gradient(A)

h e l p g r a d i e n
t
13.16
A/xA/yA/zh1h2 , h3....

[DAdx,DAdy,
DAdz, ... ]=

A/ x A/ y A/ z MATLAB

gradient(A,h1,
h 2 , h 3 , . . .)
del2(A)

z=f(x,y)P-5gradient

6.4

6.3
m a xm i ns u mp r o d

59
mean(x)

86

MATLAB 5

mean(A,dim)

1n . . . p A1
dimdim

median(x)
median(A,dim)

x
1n...p A1
dimdim

std(x)
std(A,dim)

x
1n . . .p A1
dimdim

6.5
A

MATLAB c o vc o r r c o f e

60
cov(x)

cov(A)

cov(x,y)

cov([x y])
xy

corrcoef(A)

corrcoef(x,y)

c o r r c o e f ( [ x y ]xy
)

6.6

87

(a)

(b)

(c)

88

MATLAB 5

6.4
MATLABsort
61
sort(x)

x
sort(abs(x))

[y,ind]=sort(x)

i n d y = x ( i n d ) yx

sort(A, dim)

A
dimdim

[ B , I n d ] = s o r t ( A ) I n d B B A
Ind ind
s o r t r o w s ( X , c o l ) A
a b s ( x ) a n g l e ( x )
col
6.7
A

(a) [Ascend,Ind]=sort(A)

(b)
Descend=flipud(sort(A))

4.1flipud

6.5
histbarstairs

89

62
10 x
n x
y x
y
bar(x)
x
bar(z,x)
z
xz
b a r ( x , . . ., s t r )
s t r
str13.1
bar(A)
A
stairs(x)

stairs(z,x)
z x
barh(x,A,format) mnAmn f o r m a t
1 3 . 1 s t a c k e d

barh(A)
barh x=1:m
stem(y)
xy
stem(z,y)
x x y

pareto(y,x)
y x x
x y

pie(x,extract)
x s u m ( x ) < = 1
e x t r a c t xx e x t r a c t

hist(x)
hist(x,n)
hist(x,y)

h i s tb a r s t a i r s
barpie
63

[m,y]=hist(x,n)
[m,y]=hist(x,y)
[xb,yb]=bar(y)
[xb,yb]=bar(x,y)

x10
y m i n ( x )
max(x)10 m
bar(y,m,.)
n
y
y plot(xb,yb)
x y

[xb,yb]=stairs(y)

[m,y]=hist(x)

[xb,yb]=stairs(x,y)x y

90

MATLAB 5

6.8
x
(a) hist(x)title(H i s t o g r a m o f x u s i n g h i s t)
(x)
6-2
title 13.3
hist(x)x

6-2

(b)
6-3
hist(x, 3)x

6-3

(c)

91

6-4
bar(x)

6-4 x

(d) [ m , y ] = h i s t ( x ) M AT L A B m y
b a r ( y , m ,w) 6 - 5
plot 13.1

6-5 bar

(e) stem(x) x 6-6

6-6 stem x

92

MATLAB 5

xstem(xvalues,x,-.)6-7

6-7 xvalues x x

x s t e m 3
bar

6.6
MATLAB
64
TRI=delaunay(x,y,sorted) xy
s o rt e d y
y x

voroni(x,y,TRI)

xyVo r o n o i T R I
xyDelaunay

Delaunay
65
dsearch(x,y,TRI,px,py)

(px, py ) xy
TRIxy

tsearch(x,y,TRI,px,py)

xy
(px, py) TRIxy

93

6.7

66
polyarea(x,y)

AB
dim dim

polyarea(A,B,dim)

A1
dim dim

IN=inpolygon(x,y,

xyIN(x,y)px

px,py)

p y I N 1
0.5 0

rectint(x,y)

xy

rectint(A,B)

rectint(A(i,:),B(j,:))n
mAn4Bm4

convhull(x,y,TRI)

xy
TRI

6.9
DartBoard

6-8

MATLAB

94

MATLAB 5

6-8 MATLAB

6-8

MATLAB\
M AT L A B
7 . 2

7.1
A
67
det(A)

rank(A)

AA

inv(A)

A A

pinv(A)

A Amn nm
Apinv(A)=inv(A)

trace(A)

7.1

detinvrank

96

MATLAB 5

(b)

A1

(c) A det(A1) det(A)

(d)

97

(e)

Amn r
A A r Ar=n
A MATLABorthA
A Ax=0 x MATLAB
null
v1v2...vn B=(v1 v2 ... vn)
Bn1 vi
subspace
68
orth(A)

A A

null(A)

subspace(x,y)

xy

subspace(A,B)

AB

7.2
orthnullsubspace7.1
(a)

98

MATLAB 5

(b)

(c)

Empty Matrix A1
(d)

99

(e) orth

(f)

/2 subspace

7.2 LU
MATLAB \
MATLAB
Anm bxn BXnp MATLAB
Ax=b
x=A\b
AX=B B=(b b ... b )
1

X=A\B
A
7.3
MATLAB

100

MATLAB 5

x=(x1 x2) x=A\b

M AT L A B A
MATLAB A Cholesky
L U
L U A = L UU L

L
LP
P nn

LU Ll
LL=PLl
MATLABluULP
69 LU
[L,U]=lu(A)

U LL
P

[L,U,P]=lu(A)

U L P
LU=PA

7.4
A = [1 2 3 ; 4 5 6 ;7 8 0][L,U]=lu(A)

101

A 1 (1, 1) 13
71 A11 A2
2 (2, 2) 23 A 3 A 4
U
113

223

P1P2 P

[L,U,P]=lu(A)

102

MATLAB 5

A x = b Ann b n
MATLAB Help Desk
70
x=bicg(A,b,tol,

tol

maxit,M)

norm(bA*x)/norm(b)
maxit

bicg(A,b, ...,M1,M2,x0)

M1M2
M1M2MM=M1M2
x0

[x,flag,relres,iter,
resvect]=bicg(...)

xbigcflag
iterresvect

bicgstab(... )

bicg

c g s ( . . .)

bicg

g m r e s ( A , b , r e s t a r t , restart
. . .)

bicg
.
.
.
pcg(
)

bicg
q m r ( . . .)

bicg

7.3
L U A

mn A P L
mn R PA=LR

1)
2) 1

103

3)
4) 1
MATLABrref Ax=b
71
rref(A)

rref(A,tol)

r r e f ( A ) t o l

rrefmovie(A)

tol=max(size(A))*eps*norm(A, inf) 7.6norm


7.5

(a) r r e f ( A ) A
rref(A) A
Aref=rref(A)Bref=rref(B)

(b) A A
A2B3rankA=rank(A)rankB=rank(B)

rref Ax=b B=(A b)


C=rref(B)B C
C

C(0, 0, ...,0, 1)

104

MATLAB 5

7.4 Cholesky
A A=Ax0xAx>0
G GG=A
L U C h o l e s k y L U
Cholesky
\ MATLABCholesky
chol ACholesky
72 Cholesky
chol(A)

AC h o l e s k y A

[G,err]=chol(A)

ACholeskyGA
err

R1=cholupdate(R,x)

R= c h o l ( A )x A
A+xx CholeskyR1

R1=cholupdate(R,x,-) R = c h o l ( A )x A
Axx CholeskyR1
7.6

Test=G *G

105

(b) LU Cholesky

7.5 QR
L U C h o l e s k y Q R
QR
AnnA
A=QR

Q R A A x = b
QRx=b
Rx=Qb

Q R

MATLAB qrQR mn
Amn
73 QR
[Q,R]=qr(A)

mmQ RQ
QRA=QR

[Q,R,P]=qr(A)

QRPQ
RAP=QR

[Q,R]=qr(A,0)

AQ R mn A
QnQ A
help qr

[Q1,R1]=

AjQR

qrdelete(Q,R,j)

QRAQR

[Q1,R1]=

AjbQR

qrinsert(Q,R,b,j)

QRAQRj=n+1

7.7
(a) Ax=bAb

106

MATLAB 5

A\b
(b) Q R

Q R (
7.7)
Q R G i v e n s p l a n e r o t
2Givens Givens
74 GivensJacobi
planerot(x)

x1 22 G i v e n s
MATLABqrinsertqrdelete

[G,y]=planerot(x)

GGivensy=Gx

rjr(A)

AJacobi

107

7.8
Givens 22Axy

G=planerot(x)Gx(A1)x Anew=G *AA

AAnew

( ) 7 . 6 n o r m7 - 1 A

x-y

7-1 x-y Givens

108

MATLAB 5

Givens 12.2
planerot

7.6

MATLABnorm
75

norm(x)

x 2 =

norm(x,inf)

-||x||=max(abs(x))

norm(x,1)

1- x 1 = k x k

norm(x,p)

p- x p =

norm(x,inf)

x min(abs(x))

x k n o r m ( x , 2 ) = n o r m (
x)

7.9

x=[3 4 5]

p-

7 6

normest

109

76
norm(A)

||A||2A 8.3

norm(A,1)

||A||1A 1-

norm(A,2)

||A||2norm(A)

norm(A,inf)

||A||A 1-

norm(A,fro)

Frobenius A F =

normest(A)

106

normest(A,tol)

tol

aij p-
2

7.10
(a)

(b)

110

MATLAB 5

A x = b 1
A/b x

cond(A)
A
8.3
77
cond(A)

cond(A,p)

p- p 12i n ff ro
76norm

condest(A)

A1-

[ c , v ] = c o n d e s t ( A )A1 - c v
A v =

A v

[c,v]=

cvtr=1

condest(A,tr)

tr=1c/rcond(A)

rcond(A)

A
A 0
A 1

7.11
Hilbert(4.4)
bad=cond(hilb(5))

bad

7.7
mn A x = b m>n

x m

111

\nnlslscov
9 spaugment
78
A\b

3 . 3 b=B
B

spaugment(A,c) T=[c*I A; A0]T\z


Ax=bzbcMATLAB
spparmshelp spparms

nnls(A,b)

h e l p n n l
s

lscov(A,b,v)

V(bAx ) (V1(b
Ax)help lscov

MATLAB Q R

7.12

nm Ax=b MATLAB

7.13
(a)

112

MATLAB 5

MATLABrref7.3

t
t=0.5MATLAB
(b)

ab

2/7 ax=b

(a\b) ax=b

8
MATLAB

8.1
AmnA
x n A x
A nn n
12...n
MATLAB e i g A
17.6
e i g A M AT L A B Q

A A

n o b a l a n c ee i g

79
eig(A)

[X,D]=eig(A)

A D
X AX=XD

[X,D]=

eig(A,nobalance)

balance(A)

[T,B]=balance(A)

TBB=T1AT
Bbalance

eigs(A)

A e i g

A
6 6

eigs(f,n)

A
f M n

114

MATLAB 5

eigs(A,B,k,sigma)

A BA
B= e y e ( s i z e ( A ) )k
k 6A sigma

lm ()
sm
lr
sr
be

condeig(A)

[V,D,s]=condeig(A) [V,D]=eig(A)s=condeig(A)
AMATLAB QR QZ
y
y A =y

eigA
' (3.4)
(A)m a x ( a b s ( e i g ( A ) ) )A
det(A)trace(A) A
X A n
X'X=I
8.1
A

(a) [Evect,Evalue]=eig(A)

therank=rank(Evect)
therank=
3

115

M=Evect'*Evect

A
[ X , D ] = e i g ( A ) c d f 2 r d fD
22
80
[Y,E]=cdf2rdf(X,D)

DEYA

8.2
A

[X,D]=eig(A)

116

MATLAB 5

XD [Y,E]=cdf2rdf(X,D)

EA

det(IA)=0Ipoly
11.1r o o t s e i g

Ax=Bx Bnn
x
B QZ
polyeig
81
eig(A,B)

AB

[X,D]=eig(A,B)

D X
X AX=BXD

[X,v]=

k(A0+A 1+A2+...+kAk)x=0

polyeig(A0,A1,..., vnknnk
AK)

X A0=AA 1=I

c o n d (X) = | |X|| ||X 1| | X


A

8.3

[ X X , D D ] = e i g ( A
)

117

23

22 . 0 1334
badMatrix=cond(XX)

8.2 niceMatrix=cond(X)

8.2 QRQZ

H(Hessenberg)
MATLAB
82
hess(A)

[P,H]=hess(A) P HA=P H PP
P=I
M AT L A B Q R
eig 8.4
QR QR mnA
A=QR
QmmRmn A R
qr QR7.7
83 QR
[Q,R]=qr(A)

m m Q mn

118

MATLAB 5

RA=QR

[Q,R,P]=qr(A)

mm Q
mn R P
AP=QR

[Q,R]=qrinsert

Ajb

(Q,R,j,b)

Q R QR AQ R
j=n+ 1 b A

[Q,R]=

AjQRQR

qrdelete(Q,R,j)

AQR

[Q1,R1]=

A+xyQR 1 A

qrupdate(Q,R,x,y)

QR

A Q QR
QR
1) A0=Ak=0
2) AkA k=QkRk
3) Ak+1=QkRkk=k+1
4) 2
Q R
AkA 0=A
A

QRMATLAB
8.4
QR 8.1A

1=102=43=6
1

2[Q1, R1]=qr(A1) A2=R1*Q1

119

1 0

MATLAB 12.2
Q Z MATLAB
84 qz
84 QZ
[C,D,Q,Z,V]=

CDV

qz(A,B)

QZ QAZ=CQBZ=D

QZ QZ

8.3
A U
T AT T

A TUA
A T
22 8 . 2 T
MATLABschur A
A s c h u r ( A ) A
22
rsf2csf
85
schur(A)

A T

[U,T]=schur(A)

A UA=UTU

[V,S]=rsf2csf(U,T) UT VS

120

MATLAB 5

8.5
A1A2A3

S c h 3
[V,S]=rsf2csf(U,Sch3)

ii

MATLAB S V D
svdseigs
86 SVD
svd(A)

[U,S,V]=svd(A)

S mmnn
UV S A mn

121

A=USVUAV=S
[U,S,V]=svd(A,0)

Un
Snn

svds(A,k,0)

k Ak
5 0

gsvd(A)

gsvd

MATLABA pinv(A) SVD


7.1
s i

c o n d ( A ) =s1/sn s n

(m>n)
8.6
AB

(a)

122

MATLAB 5

AB 2
(b) P s e u d o A = p i n v ( A )
PseudoB=pinv(B)

(c) AB

s1/sn

9
0
M AT L A B

9.1
MATLAB
m3 m 1 2
3 8
4 16m
9.1
A=eye(1000);

10001000 8 Mb
B=speye(1000);

1 0 0 03
1 6 K b 1 0 0 01 0 0 0 0 . 2 %

M AT L A B

9.2
AB9 . 1 2* A 2 *B
2000

MATLAB

9.2
MATLAB sparse
87
sparse(A)

A A

sparse(m,n)

mn 0

124

MATLAB 5

uva

sparse(u,v,a)

uv a (u i, v i)
a i a
max(u)max(v)
sparse(u,v,a,m,n)

mn(ui, vi)aiuva

sparse(u,v,a,m,n,

mnnzmax (ui,

nzmax)

vi)ainzmaxuv

find(x)

x x=X
X

[u,v]=find(A)

[u,v,s]=find(A)

Asuv
uvssparse
D1

spconvert(D)

2
full
88
full(S)

9.3
(a) 55
A=eye(5)

A B

(b) MATLAB

Smatrix=sparse(ind1,ind2,number)

125

Fullmatrix=full(Smatrix)

i n d 1i n d 2

whos

(c) find
Smatrix(b)

(b)

126

MATLAB 5

9.3
MATLAB


size

eyespeye
diag

[A B]AB


9.4

55
(a) C=5 *B

(b) D=A+B

(c) x=B\h

127

89
nnz(A)

spy(A)

spy(A,cstr,size) c s t r(1 3 - 1 )s i z e
A
nonzeros(A)

spones(A)

A 1

spalloc(m,n,

mnnzmax

nzmax)

nzmax(A)

A n n z ( A )
sparsespalloc

issparse(A)

A 1 0

spfun(fcn,A)

A f c n

spfun(A)

A
sprank(Arank(A)

9.5

Big=kron(A, A)

B i g K r o n e c k e r A

whosissparse
Big spy(Big) 9-1

9-1 spy

128

MATLAB 5

Big

9.4
MATLAB
90
speye(n)

nn

speye(m,n)

mn

speye(A) sparse(eye(A))
91
sprand(A)
sprand(m,n,dens)
sprand(m,n,dens,
rc)
sprandn(A)
sprandn(m,n,dens,
rc)
sprandsym(S)
sprandsym(n,dens)
sprandsym(n,dens,
rc)

sprandsym(n,dens,
rc,k)
sprandsym(S,dens,
rc,3)

9.6
(a) A

A
mndensm
n0dens1dens
1/rcmn
rc=rc ll ( m i n (m, n) )
rcil 0
A
mnsprand

S
mn
dens
1/rc 0
rc=rc
rci rc

k=1
J a c o b i 1 /rc
k=2 1/rc
S1/rc
d e n s

129

Random=sprandn(A)

A
(b) (a)A
B=sprandsym(A)

s p d i a g s A mn
p B m i n (mn)p A d
p A
di<0 di=1
di=0
di>0
92
[B,d]=spdiags(A)

A B
d

spdiags(A,d)

Ad

spdiags(B,d,A)

AB d

A=spdiags(B,d,m,n)

dB A

11.4 spdiags

9.5

L U

130

MATLAB 5

MATLAB 93h e l p
helpdesk
93
colmmd(A)

symmmd(A)

symrcm(A)

ACuthill-McKeeA

colperm(A)

A
LUlu(A(:,

j)) A

randperm(n)

Choleskychol(A(j, j))

.
.
.
12 n

dmperm(A)

ADulmage-Mendelsohn help dmperm

9.7
4

perm=randperm(4)

131

helpdesk
94
cholinc(A,opt) Cholesky opt
droptol 0
michol michol=1
rdiag

s q r t ( d r o p t o l * n o r m ( X ( : , j ) ) )

j
[L,U,P]=

X LUPopt

luinc(X,opt)

droptol
milu

udiag

d r o p t o l

thresh

95
spparms(keystr,op) help spparms
spaugment(A,c)

[c*l A; A0]
7.7

symbfact(A)

C h o l e s k yL U
h e l p s y m b f a c
t

n o r m ( f u l l ( A ) )
MATLAB

96
normest(A)

A 106

normest(A,tol)

A t o l
106

132

MATLAB 5

[nrm,nit]=

nrm nit

normest(A)
condest(A)

A1-

[c,v]=

A1- cv

condest(A,tr)

| |Av| | = ( | |A| | | |v| | ) / c t r t r= 1


tr=1 c/rcond(A)

9.8

normApprox=normest(Sprs)

theNorm=norm(full(Sprs))

difference=theNorm-normApprox

n o r m e s t
norm 7.6

e t r e e

e t r e e p l o t fi Cholesky i1
fi=0
ifi fi=0i
97
etree(A)

A f h e l p
etree

etreeplot(A)

treeplot(p,c,d)

p cd
etreeplot

treelayout
9.9
B

treeplot

133

btree=etree(B)

2 11 C h o l e s k y
12 1 2 5B
( 5 , 2 ) 2 5
spy(chol(B))Cholesky 9-2

9-2 Cholesky

9-3 B

8
1 2 235 5 6 4

134

MATLAB 5

67 78
etreeplot(B) 9-3

gplotn2n
nn 4 8
(4, 8)1

98
gplot(A,K)

Aa(i, j)0 ki kjKn


2Ann

gplot(A,K,str)

s t r s t r
13-1

[X,A]=unmesh(E)

ELaplaceA X

9.10
K A

A gplot(A,K)9-4 (0, 1)(4, 1)

9-4 gplot

10
MATLAB
MATLAB
(Bessel)

10.1 MATLAB
MATLABn p ( x ) n+ 1 p
x

A pq n+ 1m+ 1 nm
MATLAB
99
polyval(p,x)

p x x
x
x

[y,err]=

xp y

polyval(p,x,E)

p o l y f i t E
errhelp polyval
help polyfit
10.4

polyvalm(p,A)

A
p(A)=p1An+p2An1++pn+1I

poly(A)
poly(x)

A
n+1 n
nx

compan(p)

p A
p

roots(p)

pn
p(x)=0poly(roots(p))=p

conv(p,q)

pq pq

[k,r]=deconv(p,q)

pqk r
pq

136

MATLAB 5

[u v k]=
residue(p,q)

p(x)/q(x)

p(x)
u(1)
u(2)
u(j)
=
+
+ +
+ k(x).
q(x) x n(1) x n(2)
x n(j)
pq p ( x )q ( x )
u v k

[p q]=residue(u,v,x) uvx pq
mpoles

h e l p m p o l e
s

polyder(p)

n
p

polyder(p,q)

conv(p,q)

[u,v]=polyder(p,q) d e c o n v ( p , q )
u/v
10.1

MATLAB

(a) x=1

(b)

10

(c)
p5=conv(p2, p3)

(d) roots
r o o ts2=roots(p2)r o o t s 3 = r o o t s ( p 3 )

10-1

10-1 p2(x)=3x2+2x4p3(x)=2x32

(e) p(x)- p

(f) roots(poly(A))A A

usedRoots=roots(poly(A))

137

138

MATLAB 5

M AT L A B e i g ( A )

usedEig=eig(A)

(g) Ap o l y v a l m ( p o l y ( A ) , A )
=0
Cayley-Hamilton 5

10.2
MATLABM 2.9

Mg.m MATLAB

.*./.^+MATLABg
MATLAB
plot
x=linspace(0, 2);
plot(x,g(x));
grid;
t i t le('T h e g ( x ) f u n c t i ')
on

%
%
%
%

x
g ( x )

fplot
f p l ot('g', [ 0 2 ] ) ;
grid;
t i t le('T h e g ( x ) f u n c t i ')
on

% g ( x )
%
%

10

139

10-2 plotfplot13.1
f ( x ) f ( x )= 0 M AT L A B
f z e r o r o o t s 1 0 . 1f z e r o

g(x)

10-2 fplot g(x)

100

fzero(fcn,x0)

f c n
x0 eps

fzero(fcn,x0,tol)

f c n
x0 tol

fzero(fcn,x0,tol,pic)

pic

fzero(fcn,x0,tol,

fcn=fcn(x0, p1, p2,...)tolpic

pic p1 p2,...)

f z e r o ( f c n , x 0 ,
[],[],p1)

zerodemo
10.2
(a) g(x)

140

MATLAB 5

(b) s i nx2x2 sin x= 2x- 2 s i n m ( x )


Msinm.m

10-3 2
xzero=fzero('sinm', 2)

xzero =
1.4987

sinx=2x2
sin(x)-2 *x+2

10-3 sinm(x)

10

141

10.3

MATLAB
f xmin

x0x0 x minx1
xi |x minxi |

f m i n MATLAB
C
M AT L A B f m i n
fmins
f h=f
101
fmin(fcn,x1,x2)

(x1x2)f c n
x
104

fmin(fcn,x1,x2,

(x1x2)fcn

options)

x
o p t i o n s o p t i o n s( 1 ) = 1
o p t i o n s( 2 ) x 1 0 4
h e l p f o p t i o n
s

fmins(fcn,x0)

f c n
x0104

fmins(fcn,x0,

fcnhelp fmins

options)

help

f o p t i o n s

10.3
(a) [02 ]cos
c o s m i n = f m i n ( ' c o s ' , 0 ,* pi)
2

% c o s

cosmin=
3.1416

(b) 10.2 g(x) [02]

142

MATLAB 5

1 0 - 2

(c) f m i n g(x)
Mminusg.m

g
gmax=fmin('minusg', 0, 2)

MATLAB
(d) fmins
Mfx1x2.m

fmins (10)

x = l inspace(1 , 1 5 0 ) ;

% xy = x

for i=1: 50

% f x 1 x 2

for j=1: 50
Z(i, j)=fx1x2([x(i)

x(j)]);

end
end
meshc(x ,x, Z);

view(80, 10);

10

143

meshcxymeshcview
13.54.2linspace10-4

10-4 x12 +x22 - 0 . 5 x 1x2-sinx1[11][11]

10.4

i n t e r p 1i n t e r p 2

interp1(x, Y, xx ,*cubic)
MATLAB
102
interp1(x,y,xx)

x xf(x x)f
xy y=f ( x )
x

interp1(x,Y,xx)

F(x x) Y
x
x x F ( x x )
xx Y

interp1(x,y,xx,

metstr

metstr)

144

MATLAB 5

linear

nearest

spline

cubic

x
interp1q(x,y,xx)

interp1

interp2(X,Y,Z,Xx,

XxYy XYZ

Yy)

Z=f(X,Y)X
YZ

interp2(X,Y,Z,Xx,

metstr

Yymetstr)

linear

nearest

spline

cubic

VV=interp3(X,Y,Z,

XYZVXX

V,XX,YY,ZZ,

YYZZmetstr

metstr)

nearest
linear

spline

cubic

64

VV=interpn(X1,X2,
X3... ,V,Y1,Y2,

interp3 VVV
X1X2X3...*

Y 3 ,. . . , m e t h o d )

* c u b
ic

Interpft(y,n)

ny
y
y

griddata(x,y,z,

XxYy

Xx,Yy,method)

z=f(x, y) xyz
x y z
m e t h o d

linear

nearest

10

cubic
[X1,X2,X3,...]=
ndgrid(x1,x2,x3,
...)

145

v4MATLAB 4
x1x2x3...
X1X2X3...
X n n x n

[ X 1 X 2 , . . .]

[X1,X2,...]= ndgrid(x,x,x,...)

=ndgrid(x)
10.4
sinx2[02 ]40
(a) interp1 sinx 2 sin

sin

(b) xy

griddata
10.5
10 01
g r i d d a t a
10-5

146

MATLAB 5

10-5 griddata 10 linear


cubic nearest v4
%
%
%
%
%
%

A[ 01 ]
[ 0 , 1 ][ 0 , 1 ]

MATLAB 4

subplot(2, 2, 1);
mesh(X, Y, Z1);
hold on
p l o t 3 ( x , y , zo)
,
;
hold off

%
%
%
%
%

subplot(2 2 2);
mesh(X, Y ,Z2);
hold on
p l o t 3 ( x , y , zo)
,
;
hold off

%
%
%
%
%

subplot(2, 2, 3);
mesh(X, Y, Z3);
hold on;
p l o t 3 ( x , y , zo)
,
;
hold off

% 3
%

subplot(2, 2, 4);
mesh(X, Y, Z4);
hold on
p l o t 3 ( x , y , zo)
,
;
hold off

% 4
%

stps=0:0.03:1;
[X,Y]=meshgrid(stps);
Z1=griddata(x, y, z,
Z2=griddata(x, y, z,
Z3=griddata(x, y, z,
Z4=griddata(x, y, z,

X, Y);
X , c
Y ,u b i c) ;
X , n
Y ,e a r e s t) ;
X , v
Y ,4) ;

h o l ds u b p l o t1 3 . 3 m e s h g r i d1 3 . 4 m e s h
plot313.5 10-5

10

147

s p l i n e pp
ppval
103
spline(x,y,xx)

interp1(x, y, xx,

spline(x,y)

p p y=f ( x )

spline)

p ppiecewise polynomial
ppval
YI=

XYn

splncore(X,Y,XI) XIinterp2interp3interpn
ppval(pp,xx)

pp=spline(x, y)
ppval(pp,xx)spline(x,y,xx)

p=mkpp(points,

p p c o e ff(i, :)
i

coeff,d)

l = l e n g t h ( p o i n t s )1 i
n=length(coeff(:))/l

[points,coeff,l,
n,d]=unmkpp(p)
(7.7)polyfit
104
polyfit(x,y,n)

n{(xi, yi)}

[p,E]=polyfit(x,y,n)

P E p
Epolyval

10.6
xy 345

p3=polyfit(x, y, 3);
p4=polyfit(x, y, 4);
p5=polyfit(x, y, 5);
xcurve= -3.5:0.1:7.2;
p3curve=polyval(p3, xcurve);
p4curve=polyval(p4, xcurve);
p5curve=polyval(p5, xcurve);

% xy
%
% x
% x

148

MATLAB 5

10-6

10-6

5 6

M AT L A B l e g e n d r e


105
legendre(n,x)

x n
m= 0 , 1 . . . n x
[11 ] 1 m= 0 x
n

besselj(order,z)

1 o rd e r z

bessely(n,x)

2 o rd e r z

besselh(order,k,z) z H a n k e l(3 )
k Hankel
besseli(order,z)

1 o rd e r
z

10

besselk(order,z)

149

2 o rd e r
z
k= 0 k A i r yw= A i (z) k= 1

w=airy(k,z)

A i (z)k= 2 2A i r yB i (z) k= 3
Bi(z)
[w,err]=airy(...)

err

10.5
MATLAB helpdemo
(2.4)(10.1)
106
fft(x)

x x 2
FFT

fft(x,n)

nxn
xm<nm+1... n

fft(A)

fft(A,n,dim)

Adim

ifft(x)

x 1/nn
fft

fft2(A)

A
A=a fft(a)

fft2(A,m,n)

A
mn A
MATLABFFT

ifft2(A)

A 1/mn
ff2

fftn(A,Size)

n An A
S i z eX
Size

ifftn(A,Size) n An A
S i z eX
Size
fftshift(A)

A1 3 2 4
A
An(n>2)
A

150

MATLAB 5

ifftshift(A)

fftshift(A)

filter(b,a,x) ab x
h e l p f i l t e
r
Y=filter2(h,X) hF I R x Y
X
Y=filter2(h,

Y f o r mf o r m

X,form)

full

YX

same

Y=filter2(h,X)

valid
YX
10.7
hat funtion 0 , 1 0
0.51
linspace

10-7

10-7

13

11
MATLAB

11.1
MATLAB

( ) M AT L A B
q u a d g MATLAB
t r a p z

107
trapz(x,y)

xyxy
(xi, yi)x

trapz(y)
trapz(x,A)

x1
A x
A x

Z=trapz(x,A,dim)

Ad i m x
xsize(A, dim)

cumtrapz(A,dim)

A A
dimdim

quad(fcn,a,b)

[a, b]gfcng
MATLAB M

MATLAB103

quad(fcn,a,b,tol) g t o l

quad(fcn,a b,tol,
g tol
pic)

pic

q u a d ( . . ., t r a c e )

trace

152

MATLAB 5

quad8( ...)

q u a d

q = 0 s i n xdx ,
quadquad8
d b l q u a d ( f , m i n 1 , f
max1,min2,max2,

min1 max1

tol,trace,order)

m i n2m a x2 t o l t r a c e
q u a d o r d e r
d b l q u a d q u a dq u a d 8
quad

quaddemo
11.1

(a) trapz x510


xy:

(b) quadM integrand.m

11

153

(c) quad8(b)M,

MATLAB
(d) cumtrapz

(e)

11-1 M:integrand2.m:

quad xy

y15 trapz

154

MATLAB 5

11-1 meshview13.5

11-1 e-x2-y2[01][01]

f(t)dt

M AT L A B

MATLAB

11.2
ODE,
O D E

x1(t)x2(t)

dx i
= xi
dt
t

ODE 1ODE

x2x x 1 x

11

155

1ODE
0tT
t
t=T/NN
11 . 2
t ODE

MATLAB-- (R u n g e - K u t t a - F e h l b e rg) O D E

h e l p d e s k
108 t=[t0,tt]
o d e 2 3 ( 23 ) o d e 4 5( 45 ) --
xxx
108solverode45
108

--

[time,X]=

O D E s t rO D E

solver(str,t,x0)

timetime
X X

X t(1)t(2)
x0x(t(1)) strM
t
x x' (x) O D E
xx' M o d e f i l e
n u m j a c

[t,X]=

val solver

solver(str,t,x0,val) odeset11-1
ode45

ode23

ode45

ode113

ode23t

ode23s

156

MATLAB 5

ode15s

ode23s

ode23tb

set=odeset(set1,val1, set,ODE
set2,val2,...)
11-1
odeget(set,set1)

setset1

o d e s e tODE 11-1
inst=odeset(OutputFcn,odeplot);
11-1 ODE
RelTol

AbsTol

Refine

OutputFcn

o d e p h a s 2(2 D ) , o d e p h a s 3 (3 D
),o d e p l o t( ),o d e p r i n t( )

OutputSel

OutputFcn

Stats

Statson

Jacobian

O D E F ( t , y ,j a c o b i a n) d F/d y
J a c o b i a no n

Jconstant

df/dy on

JPattern

O D E F([],[],jpattern)

dF/dyJpatternon
Vectorized

O D E

F ( t , [ y 1 , y 2 . . . ] )

[ F ( t , y 1 ) F ( t , y 2..). ] on
Events

O D E events on

Mass

O D E F ( t , [ ] ,m a s s) MM(t)
on

MassConstant

M(t) on

MaxStep

InitialStep

MaxOrder

ode15s ode15s
15

BDF

o d e 1 5 s
o n

NormControl

n o r m ( e ) < = m a x ( R e l T o l *n o r m ( y ) , A b s T o l )
on

odedemo

11

11.2
(a) ODE

xprim1 Mxprim1.m

MATLABODE

11-2MATLAB 13.1 plot

11-2 xprim1ODE

(b) ODE

xprim2 Mxprim2.m

ODE

157

158

MATLAB 5

11-3

11-3 xprim2ODE

MATLAB
(c)

(b)

11-4

11-4 xprim2ODE

11

159

(d)


x1 x2
x1 =x1

2020
xprim3 Mxprim3.m

ODE

11-5
MATLAB x 2 x 1 p l o t ( x ( : , 2 ) , x ( : , 1 ) )
11-6

t0=0, tt=20

11-5 xprim3ODE

x2

11-6 xprim3
x2x1

11.3
ab

160

MATLAB 5

Mstiff1.m
function stiff=stiff1(t, x)
global a;
%
global b;
stiff=[0;0];
% Stiff

ode23s

T0 T 1
11-7
y(x) f(x)
t= 0

x=0 x=1
()11-8

11

11-7

161

11-8 ( )

y(x) g(x)
y 0 O D E

ODEy(x) ODE
x 0, x1,... ,xMxj+1=xj+x,
yjy(xj) y0yM11-9

11-9 [01]M

y(x)

ODE yj

162

MATLAB 5

11.4

f j=f(xj) M = 6 y0y 6y1, y2, . . . ,y5

y0 =T0 y M=T 1
2 1

temperature.m f(x)( )
T 0T1 9
%
%
%
%

T0 T1
x01 M 1 / M
A x = b
A

% A b

11

x=xx(2:end-1);
f=eval(funcStr);
b=deltax^2f;
b(1)=b(1)+T0;

163

% x
% f ( x )
% x = 0 , x = 1

%
y=A\b;

% y j = 1 , 2 , . . ., M - 1

y=[T0;y;T1];
% y 0 < = x < = 1
clf;
%
%

100 f(x)=x2+sin(10 x)11-10


f(x)

11-10

11.5
yj

164

MATLAB 5

M- 3 M- 3 y 2, y3 , . . . ,y M - 2
M=10
5 \

12 MATLAB
MATLAB MATLAB
MATLAB
PascalC++FORTRAN

12.1
MATLABif If

i flogical expre s s i o n( ) s t a t e m e n t( )
r e t u r n s
t r u e ()
true(
if
MATLAB
12.1
mn A A1 0 0
A1

ifelseifelse

true, statements 1 falsestatements 2

if

166

MATLAB 5

logical expre s s i o n 1t r u e s t a t e m e n t s 1 logical expre s s i o n 1


false logical expression 2truestatements 2
e l s e i f else if
elseifelse if end
if

12.2
(a) A Ax=b (A b )

% A b

(b) A 0 0

12 MATLAB

167

switch-case

logical expressionvalue 1, value 2, ...


caseexpressionotherwise
expression expression= =value
s t r c m p(e x p ression, value)
case
case 12.3
12.3

try/catch

168

MATLAB 5

MATLABexpression 1 l a s t e r r
expression 2

12.2
MATLAB forwhile

f o r d of o r
end
for

if for
f o rvariable variable

1 expressioni:j:ki:j4.3

MATLABfor v=i:j: k

12.4
(a) ( ):

for

12 MATLAB

169

;
A 2 5
A
f o r
f o r 1 2 . 2 1

diag

9
(b) [2 ,0 . 7 5 ]0 . 2 5 y=f(x) = 1 + 1 /x x
y rs

170

MATLAB 5

for

(c) MATLAB s u m ( A ) A

(d) MATLAB qrmethod.m


%
%
%
%

Amn
Q R
n
m

12 MATLAB

171

QR(8.2)3015

(e) 7.5 p l a n e r o t
0 mn
function B = Givens(A)
%
% A B mnA Q = B
R = B *A Q*R = AAQ R

22

172

MATLAB 5

% mm

A 22
QR
Atest

MATLAB

QR AtestQR=Atest
(f) f o r Helge von
K o c h 1 3

12 MATLAB

173

12-1

1.26191 2

Helge von Koch

0.5

old

oldn-1
4('old')

newold

0.5

12-2

174

MATLAB 5

12-1 von Koch

12-2 5 Helge von Koch

w h i l e f o r
endwhile while
while, statement s, end

while

w h i l e l o g i c a l e x p r e s s i o n , s t a t e m e,n tend
s

while for

12.5
(a) 1122
A=rand(2);

% 1- 1

12 MATLAB

175

disp(TheText)

lambda_1 lambda_2A

(b) ln(1+x)Maclaurin

x= 0 . 5 M a c l a u r i n e p s

176

MATLAB 5

b r e a k b r e a k

b r e a k b r e a k
break
12.6

(a) breakfor

Sun SPARC

(b) breakwhile

12.3 M
2.9 M M
inlineM 5.1.4
MATLAB

12 MATLAB

177

12.7
M sqpulse.m

n x[0.5,0.5]1
x x=1 . 7 5 s q p u l s e ( n , x ) = 1 1 . 7 5 + 2
0.25 sqpulse012-3
n

12-3 xn plot( x,sqpulse(n,x))

M %
%

l o o k f o r(2 . 7) M

12.8

178

MATLAB 5

A
b
ALU
LU
(i)
(ii)

% commenting away
12.7
MATLAB
P P M
P
109 P
p c o d e f u n 1 f u n 2...

fun1, fun2, ..., fun1, fun2, ...


.p

inplace

i n p l a c e M P

[M,MEX]=inmem

M M
M E X
MEX 15.2.115.3.1

echo

12 MATLAB

179

echoecho o necho off

110
echo fname on

fname.m

echo fname off

fname.m

echo fname

fname.m

echo on all

echo off all

c l e a r M

111 M
mlock

M clear

mlock filename

Mfilename

munlock

M clear

munlock filename

Mfilename

mislocked filename M f i l e n a m e
filename 1 0
01 ()
triu(A) triu(A,1)
112
nargin

nargout

inputname(x)

errorstr=

numbernargin

nargchk(min,

n u m b e r m i nm a x

max,number)

e r ro r s t r

varargin

varargout

12.9

random.mrandom mn v

180

MATLAB 5

v=0
function
A = Random(m,n,v)
% 0 vmn
% v v = 0

A 4B 0

vararginvarargout
12.10

v a r a r g i n
y
varargout

12 MATLAB

181

v a r a r g i nv a r a r g o u t v a r a r g i nv a r a r g o u t

12.11
test1x
function y=test1(x, varargin)

test2
function[y, varargout]=test2(x)

b a r ( x , y ) x y
[ x x , y y ] = b a r ( x , y ) xxyyp l o t ( x x , y y )
bar(x,y) bar 6.5
12.12
Mn g o n . m c n= 1 z
cn=z
n


c^n=znn
0, 1, 2

z1

c=re+i*im, k=1:n

zn

182

MATLAB 5

plot(xx, yy)

xxyyplot(xx, yy)

2 . 4 a n g l e1 4 . 2 . 11 p a t c h n g o n

subplot(2, 2, 1);

ngon(5);

ngon cn=1n=5
subplo(2, 2, 2);

cv=ngon(5, i);

p l o t ( c v ) ; e
a xqi
ua
sl)
(

c n=in=5

c n=1,n=5 rv1+i *rv2


s u b p l o t ( 2 , 2 , 4 ) ; n g o n ( i
5 , );

cn=in=5
12-4subplotplot 13

12-4 ngon

M AT L A B

MATLAB

12 MATLAB

183

g l o b a l w h o w h o s
2.3

persistent 12.13
12.13
persdemo

0 TIMEUSED

184

MATLAB 5

persdemoTIMEUSED

M
113 M
run filename

filenamefilename

pause

M (13.19(c))

pause(n)

pause off

MATLAB

pause on

MATLAB

break

f o rw h i l e
12.2

return

M MATLAB

error(str)

M str

e r r o r t r a p s t a t e s t a t e o n(
)off( )
global

global

12 MATLAB

185

c l e a r g l o b a
l
isglobal(name)

name 1 0

keyboard

M
MATLAB
k>> M

r e t u r n M
keyboard
keyboard

mfilename

warning(message) message
warning val

val
off

on

backtrace

[vt,f]=warning

debug

once

always

vt f

M M
M m a i n . m

function y=main(x)
...
z1=under1(x);
...
y=under2(a);
...
function y=under1(x)
...
function y=under2(x)
...
[b1,b2]=under3(a1,a2);
...
function y=under3(x1,x2)
...

%
%
%
%
%
%
%
%
%
%
%
%
%
%

2

1

p r i v a t e M
private

186

MATLAB 5

MATLAB M
MATLAB 2 2 MATLAB
p r i v a t e
M MATLAB

12.4
P a s c a lF O RT R A N F
f MATLAB
f Ffevalfeval
e v a l(5 . 1 . 4) MATLAB

val f F
f e v a l s i n M
feval

114
f e v a l ( f c n , x 1 ,. . . , x n )

fcn x1, ... ,xn


f e v a l

[ y 1 , y 2 ,. . . ] =

f e v a l ( f c n , x 1 ,. . . , x n )
fcn +.*, ./ ,.\, .^x
f e v a l ( f c n , x ) F f e v a l
F F e v a l e v a l
f
12.14
MATLAB f(x) x[a, b] k f

(a) feval
Aabk
A xf(x)
Functabl.m
function Y=Functab1(f, a, b, k)
% [a,b] x ( j ) = a + j* k

12 MATLAB

187

% xf ( x )

(b) e v a l e v a l
5.1.4
Aabk
A xf(x)
Functab2.m
function Y=Functab2(f, a, b, k)
% [ a , b ] x ( j ) = a + j* k
% x f ( x )
x=a:k:b;
z=eval(f);
% f x
Y=[x; z]';

o n e p l u s x( x ) = 1 +x x [11 ] o n e p l u s x
o n e p l u s x . m F u n c t a b 1F u n c t a b 2

12.5
M AT L A B s t r u c t s
C / C + + P a s c a l s t r u c t

1 2 . 1 5

188

MATLAB 5

.12.15

115

V2,...)

f1 ,f2, ...V1, V2, ...V1,


V2, ...

fieldname(S)

getfield(S,f)

Sf S.f

isstruct(S)

S 1 0

isfield(x)

S 1 0

setfield(S,f,v)

SfvS.f=v

rmfield(S,fvect)

fvect S

struct2cell(S)

handle2struct

t y p e (

struct(f1,V1,f2,

linehandlep ro p e rt i e schildrenspecial)
14
struct2handle

handle2struct

[ o u t 1 , o u t 2 ,... ]=

o u t 1 = i n 1o u t 2 = i n 2
helpdesk

d e a l ( i n 1 , i n 2 ,. . . )
12.15

structcurve

1 f u n c t i o n 2
curve

12.6
MATLAB
m e t h o d s()

12 MATLAB

189

116
class(object)

object

class(object,class,
p a r e n t 1 , p a r e n t 2 , . . .)

objectclass
p a re n t 1, parent2,...

isa(object,class)

objectclass1 0

isobject(x)

x 1 0

superiorto(class1,
c l a s s 2 ,. . . )

inferiorto(class1,
c l a s s 2 ,. . . )

methods class

class

superiorto
inferiorto

p ro p e rt i e s
@ (VA X / V M S $)
c o n s t r u c t o r
(M)
12.16
c u r v e @c u r v e @ c u r v e /
curve.m

curve
1 = curve curve
a
curve
FPLOTFPLOT
x

curve

190

MATLAB 5

1 2 . 1 6l i n e l = c l a s s ( lc,u r v e)

M
object.method())
12.17
12.16

curve.plot areacurvel
area14XMIN XMAX YMIN YMAX
12XMIN XMAX
x

curve

12-5

MATLAB

12 MATLAB

191

12-5 parabola

12.18
curve @curveM

% L1L2

l1+l2plus(l1,l2)l1l2

help o p e r a t o r n a m
e
117
117
plus(a,b)

a+b

minus(a,b)

ab

uplus(a)

+a

uminus(a)

times(a,b)

a.*b

mtimes(a,b)

a*b

rdivide(a,b)

a./b

ldivide(a,b)

a.\b

mrdivide(a,b)

a/b

mldivide(a,b)

a\b

power(a,b)

a.b

192

MATLAB 5

mpower(a,b)

ab

lt(a,b)

a<b

gt(a,b)

a>b

le(a,b)

a<=b

ge(a,b)

a>=b

ne(a,b)

a=b

eq(a,b)

a= =b

and(a,b)

a&b

or(a,b)

a|b

not(a)

colon(a,b)

a:b

colon(a,s,b)

a:s:b

transpose(a)

ctranspose(a)

a.

display(a)

a
[a b... ]

horzcat(a,b,...)
subsref(a,i)

[a;b;...]
a(i , i ,. . . ,i )

subsasgn(a,i,b)

substruct
a(i ,i ,...,i )=b

subsindex(a,b)

b(a)

vertcat(a,b,... )

builtin
118
builtin(fcn,x1,x2,... )

x1 ,x2 , . . . f c n

MATLAB C + +
c l a s s

12.7
MATLAB M
M d b
dbtype(2.9)
119

12 MATLAB

119

193

dbstop in fname

Mfname

dbstop at r in

Mfnamerr

fname

dbstop if v

v
v
errorNaNinfnaninf/infnan

dstop if warning

d b c l e a r a t r i n f n a mf
e
namer
d b c l e a r a l l i n f n a m efname
dbclear all

dbclear in fname

fname

dbclear if v

vd b s t o p i f
v

dbstatus fname

fname

mdbstatus

dbstatus

M
t r y / c a t c h 1 2 . 1 t r y / c a t c h5 . 8 ( a )
eval
120
dbstep

dbstep n

dbstep in

dbcont

dbmex

M E X 1 5 . 2 . 1 1 5 . 3 . 1
WindowsMacintosh

dbquit

M AT L A B K
K> > MATLAB
Factab.m 1!, ... ,n!
12.19
Factab.m

1!, n!

194

MATLAB 5

factorial

nn

K
Factab
Factab

6
6

12


MATLAB

12 MATLAB

195

121
dbstep in

dbup

dbdown

dbstack

12.20
Factab12.19Factabfactorial
Factab
Factroial
Factab

factorial

factorial

keyboardMATLAB

p r o f i l e

122 M
p r o f i l e c h o i c e M choice
filename

Mf i l e n a m e

196

MATLAB 5

info=profile

on,off

reset

report

report n

report

frac

fracfrac [01]

done

info
info.file

info.function

info.interval

info.count

info.state

: on off

p r o f s u m m c h o i c eM choice
n

frac

f r a c f r a c
01

str

str

profsumm

info

12.21

particle.m
8

x
y



start/finsh
minmax

StartFinish

12 MATLAB

particleBad.m
8

x
y




start/finish
minmax

StartFinish

197

198

MATLAB 5




start/finish

minmax




start/finish

minmax

profile
t = profile

12 MATLAB

199

6 . 51 3 . 1 p a r e t o1 2 - 6x
y

12-6 particleBad.m

13
MATLAB MATLAB
MATLAB d e m o

1 4

13.1
p l o t
p l o t s t r
1 3 - 1
Amn
123
plot(x,y)

x yxy (xj ,
yj)

plot(y)

j y j (j, y j)

plot(z)

,( r e a l (z k) , i m a g (z k) )
, zk

plot(A)

A mn A, n
m , nm n

plot(x,A)

AxmnAmx
Axxn
Axx

plot(A,x)

A x mnA
m x A x x
n A x x

plot(A,B)

A B ABmn
nm

p l o t ( . . ., s t r )

s t r 1 3 - 1s t r

plot(x1,y1,str1, str1y1x1

13

x2,y2,str2,...)

201

s t r 2 y 2x 2 . . . .
str1, str2 . . .
MATLAB

[1,f,p,errorm]=

str lf p

colstyle(str)

, e r ro r m

13-1

--

square

diamond

pentagram

none

hexagram

none

<

>

s t r p l o t 1 3 - 1

y+
b
13-1
13.1(g)14.2
13.1
(a)
x = [ 4 - 2 0 1 3 5
]
y = [ 1 6 4 0 1 9 2
5]

plot(x,y) 13-1
(b) MATLAB
x = pi:0.05:pi
p l o t(x,sin(x) *co s ( x ) ,' o')

13-2

202

MATLAB 5

13-2 sinxcosx

13-1 yx

(c)
x = 0 : 0 . 1 :
2
A = [ s i n ( p*
ix)0 . 5 + 0 . 5*x ]
p l o t(xA)

13-3
(d) 13-313-4
x = 0 : 0 . 1 :
2
A = [ s i n ( p*
ix)0 . 5 + 0 . 5*x ]
p l o t(Ax)

13-3 Ax

13-4 xA

(e) plot
c l e a r i
r = l i n s p a c e (2
0 )
t h e t a = l i n s p a c e 1
( 0 0 *p i )
[ xy ] = p o l 2 c a r t ( t h er
t a )
z = x+i* y
plot(z)

%
%
%
%
%
%

i
r

1 3 - 5 p o l a rq u i v e rf e a t h e rc o m p a s s
rose 13.2

13

203

13-5 z

(f) expotest.m

n, a, b
n.
[a, b]

13-6()

204

MATLAB 5

13-6()

13-6 () ()

(g) (f)

hold on hold off


130e1 e4 13-7

13-7

MATLAB e r r o r b a r p l o t

124
errorbar(x,y,e,str)

yx yi
e i s t r
13-1123 plot

errorbar(x,y,l,u,

yx, yi

str)

ui,listr

13

205

13.2
15%


15%

13-8

13-8 esinx

c o m e t c o m e t 3
13.5
125
comet(x,y)

y x

comet(x,y,l)

l* length(y)l 0.1

comet

doc comet

MATLAB
126
area(x,y)

p l o t

area(x,A)

A x
x

area(y)
area( ...,Property,

x=1:size(y,1)
area
14

206

MATLAB 5

V a l u e ,. . . )
barh(x,A,format)

mn m n
f o r m a t s t a c k e d
stackedn

barh(A)

barh x=1:m

ezplot(f,xmin,xmax)

f[xmin, xmax] xmin


x m a x 22
e z p l o t

y x

pareto(y,x)

x y
p a r e t o

pie(x,explode)

xsum(x)<=1
explodexexplode

scatter(x,y,size,

xy size

color)

()color
helpdesk

plotmatrix(X,Y)

XY

plotmatrix(X)

plotmatrix(X,X)

[ H , A X , B i g A x , p ] = H AX
plotmatrix(... )
BigAx
PBigAx(axes)
plotyy(x1,y1,x2,y2,

y1yx1y2yx2

fun1, fun2)

fun1fun2plot
fun1fun2semilogx,loglog
13.2

13.3

plotyy

Plotyy

13

207

1 3 - 9 p l o t y y l e g e n d
f t p : / / f t p . m a t h w o r k s . c o m / p u b / t e c h - s u p p o r t / l i b r a r y / g r a p h i c s / p l o t y y. m
plotyy.m

13-9 plotyy plot semilogy

13.4
areaMATLAB

13-10

13-10 area

f p l o t MATLAB

208

MATLAB 5

127
fplot(fcn,lim,str)

f c n
Mf c n . m
l i m= [x min xmax]
y
l i m=[ xmin xmax y min y max] s t r f p l o t
13-1

fplot(fcn,lim,str,

tol

tol)
fplot
13.5
sinx2
f p l ot(sin(x.^2), [ 0 , 1 0 ] ) ;

13-11

13-11 fplot sinx2

13.2
p l o t s t r
(13-1)
128
polar(theta,r) theta r

semilogx(x,y)

x10

13

209

plot(log 10(x),y),log10(0)
semilogy(x,y)

y1 0
plot(x,log 10(y)),log10(0)

loglog(x,y)

1 0
p l o t ( l o g 10 ( x ) , l o g 10( y ) ), l o g 10( 0 )

2.4
13.6
(a) plot
x=linspace(0,7);
y=exp(x);
subplot(2,1,1);plot(x,y);
subplot(2,1,2);semilogy(x,y);

%
%
%
%

x
y

s u b p l o t 1 3 . 3
13-12

13-12 ()y ()

(b) polar

%
t=linspace(0,22*pi,1100);
r = e xp(cos(t))-2* c o s ( 4 *t ) + s i n ( t . / 1 2 ) ) . ^ 5 ;
subplot(2,1,1)
p=polar(t,r);
%
subplot(2,1,2)
[x,y]=pol2cart(t,r);
%

210

MATLAB 5

% x - y

plot(x,y)

13-13()()

13-13 () ()

q u i v e rf e a t h e rc o m p a s sr o s e
13.16(b)
129
quiver(X,Y)

(Xij, Yij)(real(Z),imag(Z))
Z

quiver(x,y,dx,dy)

(xi, y i)(dxi, dyi)

quiver(X,Y,Dx,Dy)
quiver(X,Y,...,s)

(Xij, Yij)(DXijDyij)

s
s,s=1

quiver(X,Y,... ,str) str 13-1


feather(Z)

feather(X,Y)

feather(X+Y *i)

feather(Z,str)

str ;13-1

compass(Z)

compass(X,Y)

compass(X+Y *i)

compass(Z,str)

str ;13-1

rose(v)

v
36

rose(v,n)

rose(v,x)

13

211

P-5 z=f(x, y)
13.7
Z

13-14
clear i;

% i

13-14

s u b p l o t 1 3 - 3
13-14

13.3
MATLAB

1 4

MATLAB MATLAB

14

212

MATLAB 5

130
figure(gcf)

f i g u r e
14.2

shg

figure(gcf)

clf

h o l d on

clg

c l f M AT L A B

clc

home

hold on

hold off

hold

hold onh o l d o f f

ishold

hold on10

subplotsubplot

131
subplot(m,n,p)

mn, p

MATLAB subplot(mnp)

subplot

subplot(1,1,1)

13.8
(a)
clc
for I=1:10
home
A=rand(5)
pause(1);
end

%
%
%
%

(b) MATLAB f(x)=xsinx


f '(x) =xc o sxs i nx

x fy 1 1 ,y 1 2 , y 2 1 y 2 2

13

213

13-15

13-15 xsinx

subplot
13.9
M Mandelbrot
c

z i c M a n d e l b r o t c
M a n d e l b r o t 1 0 0
Mandelbrot100
% Mandelbrot
M a n d e l b r o t P r o g . m

214

MATLAB 5

clear;
r e n um=input('renu m :') ;
i m n um=input('imnu m :') ;
remin=-2;remax=1;
immin=-1.5;immax=1.5;
%

%
%
%

z!

mandelbrotmandelbrot(n,m)
Cgrid(n, m)

mandelbrot

13

215


()
Mandelbrot


13-16

13-16 Mandelbrot fractal:

14

MATLAB axis
zoom
132
axis

[xmin, xmax, ymin, ymax]


(13.5)[xmin, x max, ymin, ymaxzmin, z max]

axis(str)

str
manual
hold

216

MATLAB 5

auto

equal xy
tight x y

fill

ij

xy

image

square
vis3d
3D
normal
off

on

a x i s n o r m a
l
axis(v)

vxmin=v1, xmax=v2, ymin=v3, ymax=v4


zmin=v5, zmax=v6

axlimdlg169

axis(axis)

MATLAB
13.3hold

x l i m ( [ x m i n x m a x ] )xmin=xmin, xmax=xmax
xlim

[xminx max]

y l i m ( [ y m i n y m a x ] )ymin=ymin, ymax=ymax
ylim

[yminymax]

z l i m ( [ z m i n z m a x ] )zmin=zmin, zmax=zmax
zlim

[zminzmax]

box

b o x on
,b o x o f f b o x
3D

datetick(axis,

format axis

format)

a x i s x( )y z 2 . 5

d r a g r e c t ( X ,step)

n4X

step

grid on

(13.2),

13

217

grid off

grid

grid ongrid off

zoom on

zoom off

zoom

zoom out

zoom

zoom onzoom off

zoom(factor)

factor

zoom axis

axisxonyon

1 4 a x i s
caxissaxis 13.613.8
2.3axis(square)
axis square, grid off grid(off)
13.10
(a)
t = 0 : 0 . 2 : 2* p i + 0 . 2 ;
x=sin(t);
y=cos(t);

%
% x
% y

13-17
plot(x, y,
) ;

13-17

(b)
a x i s(square);
grid on;

%
%

13-18

218

MATLAB 5

a x i s(normal);
grid off;
axis([-2 2 -3 3]);

%
%
%

13-18 : :

t i t l e x l a b e ly l a b e l
z l a b e l M AT L A B
M ATLAB Help Desk
14.2
133
title(txt)

txt

xlabel(txt)

x txt

ylabel(txt)

y txt

zlabel(txt)

z txt

text(x,y,txt)

(x, y)txtxy
xytxt(xi, yi)
t x tx, y
i(xi, yi)

text(x,y,txt,sc)

(x, y) t x t
(0.0, 0.0), (1.0, 1.0)

gtext(txt)

13

219

t x t

legend(str1,str2,

str1, str2

...pos)

pos
1

[x, y]

(x, y)

legend(H, str1,
s t r 2 , . . .)

legend off

n u m 2 s t ri n t 2 s t rs p r i n t f (5.1.2)

13.11
(a)
particle.m
%
d i s p(G i v e t h e n u m b e r o f s t e)
ps
%
n = i nput(>>>);
x = c u m s u m ( r a n d ( n , 0
1 ) .5);
% x
y = c u m s u m ( r a n d ( n , 0
1 ) .5);
% y
c l f
%
plot(x,y);
%
hold on;
%
plot(x(1), y(1),
o, x ( n ) , y ( n )o)
,
;
% /
axs=axis;
%
s c a le=axs(2)axs ( 1 ) ;
%
t e x t ( x ( 1 ) + s c a l e / 3 0 , y ( S
1 ) ,t a r t) ;
%
t e x t ( x ( n ) + s c a l e / 3 0 , y ( F
n ) ,i n i s h) ;
%
hold off;
%

particle

13-19

220

MATLAB 5

(b)

13-20

13-19

13-20

g i n p u t

MATLAB MATLAB

134
[x,y]=ginput

MATLAB
xy

n
.
.
.
[x,y,t]=ginput(
) t1

[x,y]=ginput(n)

23ASCII
waitforbuttonpress MATLAB
waitforbuttonpress0
1
rbbox

waitforbuttonpress

zoom

13

221

13.12
MATLAB4 g i n p u t (00) (11)
MATLAB
ginput01


X,Y

get14
13.13
g i n p u tw a i t f o r b u t t o n p r e s s M AT L A B
M

f i g u r ed e l e t el i n e1 4 . 2 1 4 . 3

222

MATLAB 5

M 13-21

13-21 13.13

13.4
z=f(x, y)contour
contour3MATLAB5
135
contour(Z)

contour(Z,n)
contour(Z,v)
contour(x,y,Z)
contour(x,y,Z,n)
contour(x,y,Z,v)
c o n t o u r (. . . , s t r )
C=contourc(... )

C=contours(...)
contourf(Z)
contour3(x,y,z,n)

Z Z (x, y)
Z mn
1n 1mc = c o u t o u r ( Z )
clabelCcontourc
n n10
v
xy Z Z x
y
xy n
xyv

s t r 1 3 . 1
plot13-1
contourclabel
CC
type help contour

C c o n t o u r
t y p e h e l p c o n t o u

r
Z contour
n (x, y)
clabel

13

clabel(C)

223

Ccontourcontourc

clabel(C,v)

v C
contourcontourc

clabel(C,manual)

Z contour(Z)contour3(Z)
P-4 z=f(x, y)contourf
13.14
(a) 13-35Z13-22

13-22

(b) c o n t o u r 1 3 . 2 3 1 3 - 2 3
1 3 - 2 3 1 4

224

MATLAB 5

c o n t o u r f 1 3 - 2 4
13.23
Z
nm xy xy

13-23 15

13-24 contourf

30 11

xy [U,V]=meshgrid(x,y)
UVxyUmxV
ny13-25y

13-25 x y 45
UV xy

meshgrid
136
[U,V]=meshgrid

xyxy

(x,y)

n x x m
y y mn m
n UV xy
(u ij, vij ), i= 1 , . . . m, j= 1 ,. . .,n
Z=f(U,V)z ij=f(uij, vij)13-25

13

225

[UV]=meshgrid(x)

[U,V]=meshgrid(x,x)

[U,V,W]=

meshgrid(x,y,z)

[X,Y,Z]=cylinder

meshgrid

(r,n)

r, n
n 2 0rn
r=(1 1)n=20

cylinder(r,n)

[X,Y,Z]=sphere(n)

XYZ (n+ 1 )(n+ 1 )


n

sphere(n)

P-2 sphere
13.15
UV x5 y4
13-25 xy
% x
% y
%

z=f(x, y) Z = f ( U , V )f
3.5
13.16
(a)

contours.m

226

MATLAB 5

Z1

Z2

Z3

rotate3d13.5 13-26

13-26

(b)
g r a d i e n t(6 . 2) q u i v e r(1 3 . 2)

13

227

13-27

13-27

13.5
p l o t 3 p l o t p l o t 33
plot 13-1
137
plot3(x,y,z)

(xi, yi, zi)xyz

plot3(X,Y,Z)

XYZ

plot3(x,y,z,str) s t r
13-1
plot3(x1,y1,z1,
str1,x2,y2,z2,
str2,...)

str1 x1,y1,z1
str2x2, y2, z2...str1,str2,
...MATLAB

13.17
1 3 . 11 p a r t i c l e 3 . m


XYZ

228

MATLAB 5

13-28

13-28

:titletextxlabelylabelzlabel;13.3
138
bar3(x,A,width,

Ax width

format)

w i d t h f o r m a t
format
detached
grouped
stacked
linespec 13-1

bar3(A)

bar3(1:size(A,1),A)

bar3h(x,A,format)

Ax width

width,

w i d t h f o r m a t
format bar3 bar3

pie3(x,explode)

quiver3(x,y,z,u,

xyz

v,w,s,format)

uvw s s
1format

13

229

yx w i d t h

ribbon(x,y,width)

0.75
scatter3(x,y,z,

x, yz xyz

size,color)

scatter

stem3(x,y,A)

Axy

stem3(A)
s t e m 3 (. . . , f o r m a t )

A xy
f o r m a t f o r m a t
filled

trimesh(Tri,x,y,z) Tr i x, y, z
6
tirsurf(Tri,x,y,z) Tr i x, yz

P-6 bar3pie3
13.18
x = [ 1

4
5]

explode=[0 0 0 0 1]
x 1
0pie3(x,explode)
13-29
c o m e t
comet3

13-29

139
comet3(x,y,z)

z=f(x, y)
(xi, y i, z i)

comet3(x,y,z,p)

p*length(y) p,
0.1

MATLAB z=f(x, y)
1) 13.4
2) Z=f(U,V)UV xy
3) MATLAB

140

230

MATLAB 5

140
mesh(Z)

Z
Z

mesh(Z,C)

Z
C

mesh(U,V,Z,C)

Z
zij (xi, yj)
view
U x
V y
Z z ,zij =f(uij, vij)
C CC=Z

meshc( ...)
meshz( ...)

mesh
mesh (x, y)

waterfall(... ) meshz
hidden val

valon
offmesh.

r o t 9 0 v i e w
rotate3d
141
rotate3d val

v a l
on off

rot90(A)

90 Amesh

rot90(A,k)

k90 A

m e s h

13.19
(a)MATLAB 13.16
13.16Z1Z2Z3
Z1Z2Z3coutours
coutours

contours.m

13

231

13-30
sin(x)*sin(y)

x-0,5 *x3+0.2*y2+1

x-0,5*x3+0.2y2+1

sin(r)/r

13-30 mesh

(b) MATLAB AL UQ R
LUQR luqrmesh.m

232

MATLAB 5

A luqrmesh

Press any key when you are ready!

13-31 13-32
A

13-31 A

13-32 LUQR

MATLAB

xy
fillfill3surfsurfcsurf1 surf1

146shading interp

142
surf(X,Y,Z,C)

(X ij, Y ij, Z ij) XY


mn Z mn
(Xj, Y i, Z ij) XYM AT L A B
C

surfc(X,Y,Z,C)

CC=Z
s u r f ( . . . )

surfl(X,Y,Z,ls)

s u r f (. . . ) l s= [v, h]l s= [X, Y, Z]


view

13

233

surfl(X,Y,Z,

r=[ambient, diffuse, specular,

ls,r)

s p re a d]

surfnorm(X,Y,Z)

surf

[Nx,Ny,Nz]=

XYZ

surfnorm(X,Y,Z)

(nxij, nyij, nzij)(Xij, Yij, Zij)1

diffuse(Nx,Ny,Nz, Nx ,NyNz
ls)

ls

specular(Nx,Ny,

lsv NxNyNz

Nz,ls,v)

light

light(propstr,

propstrval

val,...)

14 14-26

lightangle

(azimuth,hight)

azimuth height

camlight

(azimuth,height) azimuth height


camlight headlight

c a m l i g h t r i g h t

camlight left
camlight(... ,

typelocal()

type)

infinite

lighting mode

s u r fp a t c h
f l a tg o u r a n d p h o n g
none helpdesk

material mode

s u r fp a t c h
s k i n yd u l lm e t a l
helpdesk

m a t e r i a l ( { k a k d helpdesk
kn n sc})

pcolor(Z)

ka

Ambientstrength

kd

DiffuseStrength

kn

SpecularStrength

SpecularExponent

sc

SpecularColorReflectance

234

MATLAB 5

Z
pcolor(X,Y,Z)

surf(X,Y,Z)view(2) 143

fill(x,y,c)

xy c
x, y c ( 1 3 - 1 )
x, y

fill3(x,y,z,c)

x, y, z xy
cc (
13-1)

13.6
P-2 light
13.20
(a) (sinr)/r

13-33
(b) XxYyZ(a)
13-34
surfnorm(Xx, Yy, Z)
sin(r)/r

13-33

13-34

13

235

13.21
s u r f 1s u r f
p e a k s 1 4

13-35

13-35

236

MATLAB 5

v i e w
13-36 viewmtx

Elevation
Azimush

13-36 view

143
view(v,h)

v x y
hhv

[v,h]=view

viewxyvxyh

view(r)

r=(x y z )

view(n)

n=2
n=3

view

44

view(T)

MATLAB44T

viewmtx(v,h,

44help viewmtx

s,r)

13.22
( a ) 1 3 - 3 3v i e w ( [ 1 0 0]) 1 3 - 3 7

13-37

13

237

(b) M a t l a b m a t r i x10 1 MATLAB


9.3
meshplot.m
Matlabmatrix.m
10Matabmatrix, MATLAB
Matlabmatrix.m.





spy

meshplot 13-38

[1, -4, 2]

13-38 MATLAB

s p y(9 . 3)

(c) v i e w
13-37 p l o t v i e w([1
0.6 0.35]) (1, 0.6, 0.35) 13-39
view([1 0.6 0.35])

238

MATLAB 5

surfmesh

13.23

MATLABXY
P a x i s
v i e w ( 2 ) f i l l
13-39

NACA0012
alpna=0
Mach =0.85. Roe
= 200*80FoilXYmat
Foil Pressure, matP

13

239

contourf



13-4013-4113-2313-2413-40P

13-40

13-41

camera camera 13-42

13-42

240

MATLAB 5

144
camdolly(dx,dy,dz, (dx, dy, dz)dirval
d i r v a l , c o o r d s y s ) :
movetarget ()
fixtarget
coordsys
camera

x
y ( )
camdolly(1,1,0)

pixels

x
y dz

data
camlookat

1414-12
camorbit(dteta,dfi, delta
c o o r d s y s , d i r v a l )dficoordsys
camera()data(camdolly)coordsys
data, dirval
campan(dteta,dfi, delta
c o o r d s y s , d i r v a l )dficoordsys
camera()data(camdolly)coordsys
data, dirval
campos

campos([x y z])

MATLAB

campos(pos)

M AT L A B p o s
automanual

campos(mode)

MATLAB

camproj
camproj(projec)

p r o j e c o r t o g r a p h i c (
)perspective

camroll(dteta)

dteta

camtarget

c a m t a r g e r t ( [ x y z
])

camtarget(pos)

M AT L A B p o s
automanual

camtarget(mode)

MATLAB

13

241

camup

up

camup(up)

upup
up

camup(pos)

MATLAB u p p o s
automanual

camup(mode)

MATLABup

camva

camva(val)

v a l

camva(pos)

M AT L A B
posautomanual

camva(mode)

MATLAB

camzoom(zoom)

z o o m 1 01

daspect
daspect(pos)

M AT L A B p o s
automanual

daspect(mode)

MATLAB

d a s p e c t ( [ x y z ] ) x, yz

pbaspect

pbaspect(pos)

M AT L A B p o s
automanual

pbaspect(mode)

MATLAB

13.24
13-33

10

10

13-43

242

MATLAB 5

13-43

MATLAB s l i c e

145
slice(V,xs,ys,

VVnx

zs,nx)

meshgrid
x s ,y szs

slice(x,y,z,V,xs

V slice

,ys,zs)

x,yz
xsyszs

13.25
f(x, y, z)=x2+y2+z2
meshgrid

2 13
(1 3 21) 1321
13-44 x=11, y=11, z=1z=11

13-44 slice

13

243

13.6
MATLAB
s h a d i n g

146
shading type

faceted

interp

flat

P-3Riemann
13.26
1 3 . 2 0
13-33
shading interp

13-45

13-45

MATLABm31
23m

colormap MATLAB
147
colordef definition

definition

244

MATLAB 5

white

colormap(Cm)

black

none

MATLAB

C m C m M AT L A B

colormap

m3

colorbar

helpcolorbar

colorbar(horiz)
c o l o r m a p ( w i n t e r ( m ) )m
MATLAB17 (13-2P-1)
13-2 MATLAB
colorcube
lines
autum
spring
summer
winter
gray
hsv
hot
cool
bone
copper
pink
flag
prism
jet
white

RGB

13.27

13-46

13-37

13

245

colorbar

13-46

148
rgb2hsv(Cm)

m3 C mrg b
rgb

hsv2rgb(Cm)

Cmm3rbg

rgbplot(Cm)

Cm

caxis(v)

v=[vmin, vmax]vminvmax

caxis

caxis(auto)

MATLAB

spinmap(t,s)

s tss=2t

spinmap(inf)

t3

brighten(s)

0<s<1 1<s<0

nt=brighten(Cm,s) Cm
contrast(Cm,m)

C m m
m Cm

whitebg

whitebg(str)

str(13-1)rgb

graymon

13.28
rgbplot

hsvrgbplot

13-47 rgbplot

246

MATLAB 5

13-47

13.7
MATLAB
p r i n t PCMacintosh

149
print

printhelp print

print filename

filename

print filename

epsfilename

deps

h e l p p r i n
t

[str,dev]=printopt

p r i n t
M h e l p p r i n t o p
t

MATLAB
SUNSolaris2.x
o r i e n t
print
150
o r i e n t l a n d s c a p e landScape
orient portrait

portrait,

orient tall

orient

13.29
MATLAB MATLAB

print -deps fig10

MATLAB

o r i e n t (1 4)

13.8
MATLAB sound

13

247

151
sound(y)

sound(y,f)

f H z
SUNSPARC

soundsc(x,

sound xsoundsc

f,slim)

ff
slim [min(x) max(x)]

13.30
(a)
x = s i n ( l i n s p a c e ( 0 , 1 0 0 0 0 , 1 0 0 0 0 ) ) ; %
sound(x);
%

(b) load
%
% y , F s : y : F s :
H z%
%
%
%

load train;
whos;
sound(y);
load chirp;
sound(y);

h e l p s o u n d
s
SUNSPARC mu-law
152 SPARC
auread(fstr)

fstr

auwrite(sv,fstr) svSun fstr


lin2mu(sv)

svmu-law

mu2lin(sv)

mu-law sv

Windows .wav
153 Windows
wavread(fstr)

fstrhelp wavread

wavwrite(sv,f,fstr)

f svfstr

14
M AT L A B
MATLAB
MATLAB
MATLAB (GUI)

MATLAB

14.1

14.1

clear;
x=0.1:0.1:4*pi;
y1=sin(x);
y2=sin(x) ./x;
figure;
subplot(1, 2, 1);
plot(x, y1);
subplot(1, 2, 2);
p l o t ( x , y 2 ,*) ;

%
%
%
%
%
%
%
%

x
y 1
y 2

xy 1y 2 1 4 - 1

14-1

14

249


s u b p l o t
p l o t1 4 . 1
14-2

14-2

14-2
y 2 *

s u b p l o t
set
14.2
2X

250

MATLAB 5

f i g u r es u b p l o tp l o t
set 1
2 x 14-3

14-3 14-1

14.2
MATLAB 5.2 14-1
14-4
14-5

1 4 - 1

line

RGB
[r g b](0r, g, b1)[1, 0, 0]
MATLABRGBblackblue
h e l p d e s k MATLAB
MATLABMATLABGUI
14-1

root

14

251
()

figure

root

axes

figure

uicontrol

figure

MATLAB
uimenu

figure

uicontext-menu

figure

image

axes

line

axes

plotplot3contourcontour3

patch

axes

surface

axes

text

axes

light

axes

14-4

14-5

252

MATLAB 5

14.2.1
MATLAB g e ts e t

14.3
(a) g f p
gfp=figure;

(100500) 400400
(b) plot14.1

(c) setgcf 155

154
set(h,prstr,alt,

h prstralt

...)

set(h,a)

h
a

set(h,pn,pv,

h pn

...)

p v

set(h,pn,pv)

h(i) pn(j) pv(i, j)h


p n
p v mn mh
npn

set(h)

set(0,Default)

14

253

ObjectNamePropertyName

set(0,DefaultObject ObjectName
NamePropertyName)

P r o p e r t y N a m e

set(h,prstr)

h p r s t r

get(h)

get(h,prstr)

h prstr

get(h,pn)

(i, j) h(i)
p n(j) p n h

get(0,Factory)

ObjectNamePropertyName

get(0,FactoryObject ObjectNamePropertyName
NamePropertyName)

get(0,Default)

ObjectNamePropertyName

get(0,DefaultObject

ObjectNamePropertyName

NamePropertyName)
allchild(h)

h(i)
14-2HandleVisibility
h
h

findobj

findobj(h,prstr,alt, prstralt
...)

p r s t r a l t
hh
p r s t ra l t
h

findobj(h,flat,
prstr,alt,...)
findall(h)

f i n d o b j ( h )
14-2HandleVisibility

copyobj(h,p)

h
p

ishandle(h)

h 0

254

MATLAB 5

1 h
10
setuprop(h,prstr,val)
p r s t r h v a l
p r s t rv a l p r s t r

getuprop(h,prstr)

h
prstr

clruprop(h,prstr)

h
prstr

handle2struct(h)

.type

.properties
.children

struct2handle(s)

.handle

.special

handle2structs

MATLAB 5 propedit set


get 170

155
gcf

gca

gco(h)

h h

14.4

get(gcf);
get(gca);

%
%

14.5
subplot
14-6

14

255

14-7

14-6 subplot

14-7

156
clf

clf reset

PositionUnitsPaperPosition
PaperUnits14-6

cla

cla reset

P o s i t i o nU n i t s
14-10

rotate(h,ax,a,o) h a a x o
[0 0 0]
remapfig(pos,

f i g pos

newpos,fig,h)

n e w p o s
posnewpos [left bottom width height]
[0 0 1 1] f i g
h h

reset(h)

h()()

delete(h)

close(h)

h h h

close name

name

256

MATLAB 5

close all

HandleVisibility14-2

close all hidden


status=close(...) status10
hgsave(h,filename) h f i l e n a m e
filename .fig
hgload(filename) f i l e n a m e ( )
filename.fig

14.2.2

14-2
ButtonDownFcn

MATLAB

Children

Clipping

o n( )

CreateFcn

M MATLAB

off

s e t ( 0 , D e f a u l t F i g u r e C r e a t e F c nfu,
n c t i o n
)
f u n c t i o nM MATLAB
DeleteFcn
BusyAction

M MATLAB
M AT L A B I n t e r r u p t i b l e (
)o f fB u s y A c t i o n
q u e u e

( )

c a n c e l
HandleVisibility

C h i l d r e n
o n

()

c a l l b a c k

o f f
HitTest

H i t T e s t
o n( ) o f f 1 5 5 g c o
14-7 C u r r e n t O b j e c t

Interruptible

I n t e r r u p t i b l eo n(
) I n t e r r u p t i b l e
o f f

Parent

14

257
()

Selected

o no f f

SelectionHighlight

Tag

Type

UserData

o n(

)o f f

UIContextMenu

M AT L A B
14.2.8

Visible

o n()o f f

14.2.3
MATLABs e tg e t

14-3
Automatic-FileUpdates

o no f f

CallbackObject

[ ] 171g c o b

Language

CurrentFigure

[ ]

Diary

o n

DiaryFile

D i a r y

Echo

Monoff()

155g c f
o f f()

ErrorMessage

MATLAB

Format

MATLAB s h o r t
s h o r t E()s h o r t Gl o n gl o n g El o n g Gb a n k
h e x+r a t i o n a l

FormatSpacing

MATLAB l o o s e(

PointerLocation

PointerWindow

MATLAB

)c o m p a c t

0
Profile

p r o f i l e

ProfileFile

p r o f i l e ()

ProfileCount

p r o f i l en1 kM

o no f f()

kp r o f i l e
ProfileInterVal

p r o f i l e

RecursionLimit

MATLAB

ScreenDepth

258

MATLAB 5

()

ScreenSize

[left bottom width height]

ShowHidden-

HandleVisibilty

Handles

o n

off()

Units

14-2

p i x e l s()
n o r m a l i z e d

i n c h e s

c e n t i m e t e r s

Parent

p o i n t s

0.353

c h a r a c t e r s

[]

MATLABX Windows
14-4 X Windows
TerminalHideGraphCommand

TerminalShowGraphCommand

TerminalOneWindow

on()off

TerminalDimensions

TerminalProtocol

n o n e

XX Windows

t e k 4 0 1 x

Tektronix 4010/4014

t e k 4 1 0 x

Tektronix 4100/4105

14-5

14.6
0

14.2.4

14

259

set

157
prstralt

figure(prstr,alt,
. . .)

figure(f p)

f p

refresh(f p)

f prefresh

drawnow

MATLAB plot
plotdrawnow

newplot

NextPlothelp newplot

fignamer(str)

str
Name

setptr(h,cursor)

h cursor help
setptr
Pointer

p=getptr(h)

h p
setptr(h,p{:})
Pointer

14-6
BackingStore
IntegerHandle
MenuBar
Name
NextPlot

NumberTitle

o n()o f f

I n t e g e r H a n d l eo n() o f f
MATLAB f i g u r e(
)n o n e()

a d d
()
r e p l a c e

clf reset
replace children
clf

N u m b e r T i t l e o n( ) F i g u r e N o . N :
N a m eName()NumberTitleoff

260

MATLAB 5

()

Name
Pointer

c r o s s h a i ra r r o w( )w a t c ht o p lt o p r
b o t lb o t rc i r c l ec r o s sf l e u rl e f tr i g h t
t o pb o t t o mf u l l c r o s s h a i ri b e a mc u s t o m

PointerShapeCData

1616Pointercustom

PointerShapeHot-

PointerShapeCData12NaN

Spot

P o i n t e r S h a p e C D a t a ( )
[ 11 ]

Position

[left bottom width height]

Renderer

p a i n t e r s
z b u f f e r p a i n t e r s

OpenGLpainterszbuffer

RendererMode

R e n d e r e r M o d e a u t o ( )
MATLABm a n u a l
MATLAB

Units

MATLAB
p i x e l s

()

n o r m a l i z e d

i n c h e s

c e n t i m e t e r s
p o i n t s

0 . 3 5 3

c h a r a c t e r s

C u r r e n t P o i n tP o s i t i o n
WindowStyle

o r m a l()m o d a l
( )
n o r m a l V i s i b l e o f f
MATLAB C o n t r o lC

Clipping

Parent

SelectionHighLight

14-7
CloseRequestFcn

(c l o s e r e q)

CurrentCharacter

CurrentAxes

155g c a

CurrentObject

C u r r e n t P o i n t
155g c o

14

261
()

Cu r r entPoint

KeyPressFcn

MATLAB

Resize

o n

()o f f
ResizeFcn
SelectionType

U N I Xn o r m a l(
) e x t e n d e d ( s h i f t ) a l t e r n a t e
( c o n t r o l )o p e n()

WindowButtonDownFcn

W i n d owButton

MotionFcn
WindowButtonUpFcn

14-8
Color

RGB MATLAB

Colormap

m3 m R G B ()
64 13.6

Dithermap

m3 ( ) (8 )
64

DithermapMode

(8)
manual()Dithermap
()autoMATLAB
automanual

FixedColors

m3 ( )C o l o r m a p

MinColorMap

M AT L A B C o l o r m a p
C o l o r m a p 64

ShareColors

MATLABC o l o r m a p o n()o f f
C o l o r m a p o f fh e l p d e s k

14-9
InvertHardCopy

o n

PaperUnits

MATLAB
n o r m a l i z e d

o f f
i n c h e s()c e n t i m e t e r s p o i n t s
P a p e r S i z eP a p e r P o s i t i o n
PaperOrientation

p o r t r a i t( )
l a n d s c a p e()

PaperPosition

[left bottom width height]

262

MATLAB 5

()

PaperPositionMode

PaperPositionMode
m a n u a l( )M AT L A B P a p e r P o s i t i o n( )
P a p e r P o s i t i o n M o d ea u t o

PaperSize
PaperType

[width height]

usletter()
uslegal

A0

A1

A2

A3

A4

A5

B0

B1

B2

B3

B4

B5

archA

archB
archC
archD

arcE

A
B

C
D

E
tabloid

14.7
(a)

(b)

14.2.5

158
axes(prstr,alt,... )

p r s t r a l t

axes(h)

s u b p l o t

14-10
Box
CurrentPoint

o no f f()
23

DataAspectRatio
DataAspectRatioMode

[dx dy dz] xyz


M AT L A B

x y z

D a t a A s p e c t R a t i o M o d e a u t o ( ) M AT L A B
DataAspectRatiomanualDataAspectRatio

14

263
()

D a t a A s p e c t R a t i o D a t a A s p e c t R a t i o M o d e
manual
DrawMode

n o r m a l( )f a s t
( )R e n d e r e r
z b u f f e r

LineStyleOrder

*| :
|oLineStyleOrder-

LineWidth

XYZ 0 . 5

NextPlot

a d d

()

r e p l a c e

( ) cla reset

r e p l a c e c h i l d r e

n
c l a
PlotBoxAspectRatio

[p x p y p z] * L i m (1 4-1 3 ) x
yz

PlotBoxAspect-RatioMode

M AT L A B xyz
a u t oMATLABP l o t B o x A s p e c t R a t i om a n u a l
P l o t B o x A s p e c t R a t i o P l o t B o x A s p e c t R a t i o
P l o t B o x A s p e c t R a t i o M o d em a n u a l

Projection

P r o j e c t i o no r t h o g r a p h i c

p e r s p e c t i v e
r e a l

Position

[l e f t b o t t o m w i d t h h e i
]
ght

Title

Units

i n c h e s
c e n t i m e t e r sn o r m a l i z e d( )p o i n t sp i x e l s
c h a r a c t e r s P o s i t i o n

View

C a m e r a P o s i t i o nC a m e r a U p V e c t o rC a m e r aV i e w A n g l e 1 4-1 2 v i e w

14.8
subplotaxes

264

MATLAB 5


(-37.5, 30)

14-8 axes

[01] 14-8

14-11
AmbientLightColor

RGB MATLAB

CLim

[cmin cmax](CData)
C o l o r m a pc m i n
cmax C D a t a cmincmax
cmincmax

CLimMode

M AT L A B C L i m C L i m M o d e a u t o
MATLABCDataCLimMode
manual
CLimCLimCLimModemanual

Color

n o n e
RGBMATLAB

ColorOrder

m3RGB p l o tp l o t 3

14

265

MATLABcameracamera

14-12
CameraPosition
CameraPositionMode

[x y z]
MATLABCameraPositionMode
a u t o M AT L A B C a m e r a P o s i t i o n M o d e
manual CameraPositionModeCameraPosition
CameraPositionModemanual

CameraTarget

[x y z]

CameraTargetMode

M AT L A B
CameraTargetModeautoMATLABCameraTarget
manualCameraTarget
CameraTargetCameraTargetModemanual

CameraUpVector

[x y z]

CameraUpVectorMode

MATLABCameraUpVectorCameraUpVectorMode

[0 0 1]z
auto
CameraUpVector[0 0 1]
CameraUpVector[ 0 1 0]CameraUpVectorMode
manualCameraUpVectorCameraUpVector
CameraUpVectorModemanual

CameraViewAngle

( 01 8 0)

CameraViewAngleMode

MATLAB C a m e r a V i e w A n g l e M o d e
a u t oMATLABC a m e r a V i e w A n g l e M o d e
m a n u a l
C a m e r a V i e w A n g l e C a m e r a V i e w A n g l e M o d em a n u a l

*XYZ
14-13
GridLineStyle

,, : ( )
.n o n e 1 3 2 g r i d

Layer

View[0
90]DrawModefast 14-10Layer
bottom()top

TickLength

[ 2D l e n 3D l e n]
T i c k L e n g t h

TickDir

o n
o u t

TickDirMode

MATLAB T i c k D i rT i c k D i r M o d ea u t o
T i c k D i r m a n u a l T i c k D i r
T i c k D i r T i c k D i r M o d em a n u a l

XAxisLocation

x b o t t o m( )
t o p

YAxisLocation

()y l e f t( )
r i g h t

266

MATLAB 5

()

*Color

RGB MATLAB * *
w h i t e()

*Dir

*normal()reverse

*Grid

* o n o ff ( )
g r i d 132

*Label

*Lim

[min max]*

*LimMode

MATLAB *L i m *L i m M o d e a u t o
*L i m m a n u a l *L i m *L i m
*L i m M o d em a n u a l

*Scale

* l i n e a rl o g

*Tick

*TickLabel

*TickLabelMode

MATLAB *T i c k L a b e l*T i c k L a b e l M o d e
a u t o * T i c k L a b e l m a n u a l
*TickLabel*TickLabel*TickLabelModemanual

*TickMode

MATLAB *T i c k *T i c k M o d e a u t o
*T i c k m a n u a l *T i c k *T i c k
*T i c k M o d em a n u a l

14-14
FontAngle

n o r m a l(

FontName

FontSize

F o n t U n i t s

FontUnits

F o n t S i z e i n c h e s

)
i t a l i co b l i q u e

c e n t i m e t e r sn o r m a l i z e dp o i n t s()p i x e l s
FontWeight

lightnormal()demi
bold

12
5 XTickYTick
14.9

X
y

14

267


X
X


y
y


xy
xy

14-9

14-9

14.2.6
G U I G U I

GUI 14.3
159
uicontrol(f p,
prstr,val, ... )

f p
f p
p r s t ra l t
( )

268

MATLAB 5

CallBack
[outstr,pos]=

instrh instr

textwrap(h,instr)

outstr
pos

popupstr(h)

h()
Stylepopupmenu

14-15
BackgroundColor

RGBMATLAB

Callback

f r a m e
t e x t

CData

R G B m n 3 p u s h b u t t o n
t o g g l e b u t t o n

Enable

o n

() C a l l b a c k

i n a c t i v e B u t t o n D o w n F c n
o f f

B u t t o n D o w n F c n (
String)

Extent

[0 0 width height]S t r i n g

ForegroundColor

RGBMATLAB S t r i n g

Horizontal

String
left

center()right

Alignment
ListboxTop

l i s t b o x S t r i n g

Max

V a l u e ()

r a d i o b u t t o n
c h e c k b o xt o g g l e b u t t o no n
V a l u eM a x
s l i d e r
e d i tM a xM i n > 1
listbox MaxMin>1
f r a m ep o p u p m e n ut e x t
Min

V a l u e ()
r a d i o b u t t o n c h e c k b o x t o g g l e b u t t o n
o f f V a l u eM i n
s l i d e r
e d i tM a xM i n > 1
listboxMaxMin>1
f r a m ep o p u p m e n ut e x t

Position

[left bottom width height]

14

269
()

p o p u p m e n u S t r i n g

String

|
(popupmenu,listbox)\n(edit,text)
l i s t b o xe d i tt e x t

p u s h b o t t o n()

Style

radiobutton

checkbox

edit()
text
slider
frame
listbox
popupmenutogglebutton(/)
[minstep maxstep]

SliderStep

[ 0 . 0 1 0 . 1
]
TooltipString

Units

inches
centimeters

normalized

points
pixels(
)characters
ExtentPosition

Value

r a d i o b u t t o nc h e c k b o xt o g g l e b u t t o n
M a xM i n
s l i d e r
p o p u p m e n
l i s t b o x

Children

[ ]

Clipping

HitTest

14-16
FontAngle

FontName

FontSize

FontUnits

FontWeight

14-13
14.2.7

160
uimenu(p,prstr,alt, p
...)

p
p
p r s t ra l t
p r s t r a l t

270

MATLAB 5

makemenu(h,mencho, h mencho
calls,tags)

c a l l s
MATLAB
t a g s
Ta g (1 4 - 2 ) m a k e m e n u
h e l p m a k e m e n
u
menuedit 14.3.5

umtoggle(h)

h
1 0
Checked

winmenu(h)

h Wi n d o w
h WindowTag
winmenu14-2help winmenu

14-17
Accelerator

ControlAccelerator
MacintoshCommandAccelerator

Callback

Checked

o no f f()

Enable

o n()o f f o f f

ForegroundColor

() R G B MATLAB

Label

&

X Windows

Position

Separator

o n o f f(

ButtonDownFcn

Children

Clipping

Selected

SelectionHightLight

UIContextMenu

14.2.8
U i c o n t e x t m e n u M ATLAB 5.2

14

271

(M a c i n t o s h C o n t r o l)

14-2 UIContextMenu
161
uicontextmenu
(prstr,alt, ...)

prstralt

Uicontextmenu
14-18 Uicontextmenu
Callback

(Macintosh C o n t r o l)

Children

ButtonDownFcn

Clipping

HitTest

Selected

SelectionHighlight

UIContextMenu

14.10

(MacintoshControl)14-10

272

MATLAB 5

14-10

14.2.9
MATLAB MATLAB
MATLAB
i m a g e
c a p t u r e c a p t u r e
image MATLAB
162
image(C)

C C
C

image(x,y,C)

C xx xy

image(prstr,alt,
. . .)

p r s t ra l t

i m a g e s c (. . . )

image

capture(h)

set

[C,Cm]=capture

Cm C

imfinfo(filename,

filename

fmt)

f m t

b m p

h d fj p gj p e gp c xt i ft i f f
xwdhelpdesk
[ A , F t a b ] = i m r e a d filename AFtab
(filename,fmt,idx) f m t

14

273

M AT L A B
( t i f f h d f
) i d x
helpdesk
imwrite(A,Ftab,

filename,fmt,

fmt fmt hdf

prstr,alt)

j p e gt i f f
prstralthelpdesk

P-7imagecolormap(map)

14-19
CData

CDataMapping

14-21

EraseMode

14-20

Xdata

1s i z e ( C D a t a , 2
)
x

YData

1s i z e ( C D a t a , 2
)
y

Children

[ ]

14.11
image 14-11

14-11 image

14.2.10
l i n e p l o t
line plotline
plot

274

MATLAB 5

163
X y X y

line(x,y)

line(x,y,z)

line(prstr,alt,
...)

prstralt

14-20
Color

RGB MATLAB

EraseMode

n o r m a l

( )

n o n e
x o r

(XOR)

b a c k g r o u n d

LineStyle

(): none

LineWidth

0.5

Marker

+o * . x
s q u a r e
d i a m o n d
^
v
>
<
p e n t a g r a m
h e x a g r a m
none()

MarkerSize

6MATLAB1/3

MarkerEdgeColor

R G B

MATLABn o n ea u t o( C o l o r
)
MarkerFaceColor

R G B M AT L A B
n o n ea u t o( C o l o r)

XData

YData

ZData

Children

[]

14.2.11
x
yz patch
164
patch(x y c)

xyc
CDataFaceVertexCData

14

275

xy

patch(x,y,z,c)
patch(prstr,alt, prstralt
. . .)

14.12

sphere(10);

% 1 2 1

x = [22 2 2 ] ;
y = [2 2 22];
z = [222 2];
c = [21 1 2] ;

%
%
%
%

x
y
z

p 1 = p a t c h ( x , y , z , c ) ;% p 1

14-12

14-12 patch

setget
14-21
Cdata

C D a t a M a p p i n g
RGBMATLAB

RGB m3
RGB mn3

R G B

C o l o r m a pD i t h e r m a p1 4 - 8C D a t aN a NMATLAB
F a c e V e r t e x C D a t a
CDataMapping

CdataFaceVertexCDatacolor index

()

ColorMap(14-18)
s c a l e d() MATLAB
Clim

276

MATLAB 5

()

d i r e c tColorMap
( 1)
FaceVertexCData

RGB
(C D a t a M a p p i n g)
m3mF a c e s R B G m1(
C D a t a M a p p i n g) Cdata

EdgeColor

R G B M AT L A B
b l a c k()
n o n e
f l a t
interp CDataFaceVertexCData

EraseMode

14-20

FaceColor

RGB()
n o n e
f l a t
i n t e r p

Faces

mnnm
NaN
helpdesk

LineStyle

14-20

LineWidth

14-20

Marker

14-20

MarkerEdgeColor

1 4 - 2 0 a u t o E d g e C o l o r
f l a t

MarkerFaceColor

1 4 - 2 0 a u t o C o l o r
none flat

MarkerSize

14-20

Vertices

m3 xyz F a c e s

XData

xXdata
xXDataYDataZData

YData

X D a t a y

ZData

X D a t a z

Children

MATLAB14-26
14-22
FaceLighting

n o n e

()

f l a t

14

277
()

g o u r a n d

EdgeLighting
BackFaceLighting

AmbientStrength
DiffuseStrength
SpecularStrength
SpecularExponent
SpecularColorReflectance
VertexNormals
NormalMode

phong
gourand

F a c e L i g h t i n g
14-12
u n l i t

l i t

r e v e r s e l i
t
()

01 ( )
A m b i e n t C o l o r
01
01
1 m i r r o r - l i k e n e s s 15 0 0
520
01
0 1
A m b i e n t L i g h t C o l o r14-11
m3 m

MATLAB V e r t e x N o r m a l sN o r m a l M o d e
a u t oMATLABV e r t e x N o r m a l s m a n u a l
VertexNormalsVertexNormalsNormalMode
m a n u a l

14.2.12
165
surface(x,y,Z,c) xyZ
x y Z 1 4 - 2 3
X D a t aY D a t aZ D a t a c
1 4 - 2 3C D a t a c c=Z

surface(prstr,
alt, ...)

prstralt

14-21
14-23
CData

ZDataFaceColor
texturemap
CDataZDataCData
Z D a t a 1 4 - 2 1

278

MATLAB 5

()

CDataMapping

14-21

EdgeColor

14-20

EraseMode

14-21

FaceColor

14-21 t e x t u r e m a pCDa t a

LineStyle

14-21

LineWidth

14-21

Marker

14-21

MarkerEdgeColor

14-21

MarkerFaceColor

14-21

MarkerSize

14-21

MeshStyle

/b o t h()r o wc o l u m

XData

mnm1( mn) x

YData

mnm1( mn) y

ZData

mnm1( mn) z

Children

(1 4 - 2 4 )
14-22
14-24

14.13
(a) 14.12
[X, Y, Z]=sphere;
ss=surface(X,Y,Z);
view(3);

%
%

set FaceColorflatinterp
set(ss, FaceCol o r, i n t e r p)

FaceColor

F a c e C o l o r p a t c h s u r f a c e m e s h
texturemap interpflat none
(b) m e s h s u r f a c e
patchmesh
X1 Y1Z1

14

279

XXYYZZ

(2)

14-13

14-13

14.2.13
t e x t

166
(xy)
txt
text(x,y,z,txt) txt
text(prstr, alt, prstr alt
text(x,y,txt)

...)

280

MATLAB 5

14-25
Color

R G B M A LTA B
w h i t e()14-20

EraseMode

14-20

Editing

o f f
o n
ESC E d i t i n go f f

Extent

[left bottom width height] ( )


S t r i n g

FontAngle

normal()
italicoblique

FontName

14-14

FontSize

14-14

FontUnits

14-14

FontWeight

14-14

Horizontal

left()
centerright

Alignment
Position

[x y][x y z]

Ratation

String

Units

i n c h e s
c e n t i m e t e r s n o r m a l i z e d p o i n t s p i x e l s
c h a r a c t e r s d a t a( )
P o s i t i o nE x t e n t

Interpreter

S t r i n g

( t e x n o n e)

h e l p d e s k
VerticalAlignment

top

cap(top
)
middle()
baseline(y)bottom

Children

[]

14.14

14

281

14-14

14-14

14.2.14
MATLAB 5

AmbientStrengthDiffuseStrength
EdgeLightingFaceLightingBackFaceLightingSpecularStrengthSpecularExponent
SpecularColorReflectanceVertexNormals
14-2214-24
14-11AmbientLightColor
167
light(prstr, alt,) p r s t r a l t

282

MATLAB 5

P-2P-8light

14-26
Position

[x y z]

Color

RGB MATLAB

Style

i n f i n i t e () P o s i t i o n
l o c a l

P o s i t i o n

ButtonDwnFcn

Children

[]

Clipping

HitTest

Interruptible

D e l e t e F c n

Selected

SelectionHighlight

UIContextMenu

14.15

phong

14-15

14

283

14-15

14.3
MATLAB
168
dialog(prstr,alt,... ) prstralt

msgbox
msgbox(message,

title,icon,icondata,

iconclr,mode)

m e s s a g e
title
i c o n
n o n e e r r o r h e l p
warncustom
c u s t o micondata
iconclr
m o d e
m o d a ln o n m o d a l
r e p l a c e

284

MATLAB 5

helpdlg(hlpstr,title) t i t l e h l p s t r

helpwin topic

MATLAB t o p i c
M
S e e A l s o

helpwin(hlpstr,

headingtitle

heading,title,prstr,
alt, ... )

hlpstr
\n
prstr
alt

helpwin(r1 t1;
r2 t2;... ,page,

(r 1r 2. . . t 1t 2. . .)

page
.
.
.
t i t l e , p r s t r , a l t , )
r1
warndlg(warn, title)

w a r n
title

errordlg(errstr,

title

title,on)

o n title
t i t l e

questdlg(qst,

qsttitle

title,alt1,alt2,alt3, YesNo
C a n c e l a l t 1a l t 2a l t 3
( ) d e f a u l t

Y e sN o C a n c e l
a l t 1a l t 2a l t 3

inputdlg(legend,

l e g e n d

title,lineNr,dfltAns) titlelineNr
()dfltAns

menu(title, alt1,
alt2,...)

titlealt1alt2

14

285

m e n u
Interruptible yes
[s e l e c t i o n , o]k=

listdlg(ListString, p r s t r a l t
S,prstr,alt,... )
helpdesk
selection
S o k O K
ok=1ok=0(selection)
[f n a m e , p a t]h=

f i l t e r

uigetfile(filter,

wildcards
*m

t i t l e , x , )y

M t i t l e x
y
f n a m ep a t h

[f n a m e , p a t]h=

uiputfile(filter,title,x,y)
pagedlg(f ig )

fig fig

printdlg(
-crossplatform,
fig)

fig
f i g
c r o s s p l a t f o r m M AT L A B

uisetcolor(x, title)

x
R G B
x t i t l e
R G B
0

uisetfont(pr, title) t i t l e
p r
p r
p r
0
btngroup(h,prstr,
val, ... )

h
h
p r s t ra l t
h e l p b t n g r o u
p

286

MATLAB 5

btndownbtnup
b t n i c o nb t n p r e s sb t n s t a t e
help

tabdlg

helptabdlg

waitbar(x , t i t l e
)

x
title
x(01)

169
axlimdlg

h e l p a x l i m d l
g

edtext

h e l p e d t e x
t
plotedit

help plotedit

14.16

XWindows 14-16

14-16 menu
MENU

Enter Wait LeaveWait

M AT L A B

14

287

G u i d e( )
s e tg e t( 1 5 4 ) G u i d e

170 Guide
ctpanel(h)

Guide
h h

guide(h)

G u i d e h
h

propedit(h)

h h
h

align

helpdesk

cbedit(h)

h
h

menuedit(h)

h h

Guide

G u i d e

G u i d e (
170)
X W i n d o w s Wi n d o w s
M a c i n t o s h

288

MATLAB 5

MATLAB MATLABGUI

14.3.1
MATLAB g u i d e Guide
1 4 - 1 8

14-17

14-18 Guide

1 4 - 1 7 G u i d e 1 0

14.17

uisetcolor(168)

14

289

(slider)
(edit)
(frame)
(text)
(p u s h b u t t on)CANCELOK

14-19

14-19

14.3.2
(14-20)

/
/

14-20

290

MATLAB 5

(1 4 - 4 )
+

(s h i f t )

Multiple Values

col Color

14.18
14.17

(figure)

(slider)

(text)

(edit)

14

291

(text)

(frame)

(text)

(pushbutton)

14-21

14-21

14.3.3
14-22

292

MATLAB 5

14-22

A p p l y R e v e r t

14.19
14.17 14-23

14-23

14

293

Controlled #1:Color Picker


ColorPicker.m
M M AT
C o l o r P i c k e r. m a t

14.3.4
Callback Editor 14-24

14-24

14-24

MATLAB
M M
MATLAB c l e a r f u n c t i o n
s
MATLAB
171
[h,f i g]=gcbo

h
[]f i g

gcbf

[ ]

294

MATLAB 5

selectmoversize

B u t t o n D o w n F c n
A
A.Type S e l e c tM o v eR e s i z e
C o p yA.Handles (S e l e c t)
m2
(Copy)

overobj(type)

t y p e
U n i t s
pixels

setstatus(h,str) S t r i n g
S t y l e t e x t T a g S t a t u s
14-15 h
getstatus(h)

String

hidegui(h,status) h HandleVisibility14-2
hstatus
onoffcallback

status=hidegui(h) h H a n d l e V i s i b i l i t y
h
waitfor(h,prstr, hControl C
alt)

p r s t r
a l t p r s t r a l t h
p r s t r a l t

uiwait(h)

h
u i r e s u m e
h

uiresume(h)

uiwait

status=

uisuspend(h)

status
uirestore

uirestore(status) u i s u s p e n d

status

uisuspend
14.20
14.17 Active #1:Color Picker Guide

14

295

Callback

CbColPic redsl;

CbColPic redtxt;

CbColPic greensl;

CbColPic greentxt;

CbColPic bluesl;

CbColPic bluetxt;

Cancel

CbColPic cancel;

Ok

CbColPic ok;

MCbColPic.m

296

MATLAB 5

UserData





100
0

14

297

LocalChStr(InStr) I n S t r

LocalUpdataCol

Controlled #1:Color Picker

14-25

14-25

14.3.5
Menu Editor 14-26

14-26

298

MATLAB 5

G u i d e

New Menu
New Context Menu 14.2.8
Label
Tag
C a l l b a c k
M ()

14.21
14.17 CANCELOK

Active #1:Color Picker

MCbColPic.m

14

299

Controlled #1:Color Picker


14-27

14-27

C A N C E L O K O K

C A N C E L
uicolor.m

300

MATLAB 5



UserData

R G B

14

301

U s e r D a t a O K
CANCEL
MCbColPin.m

uicolor(ColorPicker
)

14.4
14.4.1
13.8
14.22

302

MATLAB 5


20

10
!

14.4.2
getframe
172
p

getframe(p,r)

p
r r
[left bottom width height]
[X,Ftab]=getframe(... )

XFtab

[X,Ftab]=frame2im(F)

F XX F t a b

14.4.3
m o v i e i n

173
moviein(n)

n
14.22

14

F=

303

X FX Ftab

im2frame(X,Ftab)

14.4.4
movie
174
movie(p,Mat,n,fps,

n Matfpsn

pos)

p o s= (x, y ) xy
Units p

15 MATLAB
M AT L A B

F O RT R A N C

FORTRANCMATLAB MATLAB
CFORTRAN M A LTA B

MATLAB Microsoft Word for Windows

15.1 MATLABF O RT R A NC
M AT L A B F O RT R A NC F O RT R A NC
MATLAB MATLAB
for-loops
FORTRAN 77CMATLABFORTRAN 90C++
FORTRANCMATLAB

MATLAB M E X MATLAB
M
2 . 8 MATLAB M AT C
FORTRAN
Wi n d o w s M ATU N I X 1 5 . 4
MATLAB
MATLAB C C + + MathWorks
MEXC C
CMATLAB M A LTA B

M ATLAB 5
mxArrays mxArrays
MATLAB 5 C
FORTRAN
CFORTRANMATLAB
mx

mxArrays

mat

MAT

eng

MATLAB

mex

MEXMALTAB

MATLABCFORTRAN

15 MATLAB

305

Sun OS 5.5.1 Soloais CDE 1.0.2Windows

MATLAB
.../matlab52/extern/examples

...
MATLABh e l p d e s k MATLAB

15.2 MATLABC
CMATLAB CANSI C
15.2.1 CmxArray
mxArray
matrix.h
#include "matrix.h"

MATLAB MATLAB (
195mexMakeArrayPersistentmexMakeMemoryPersistent)
175 C
void *mxCalloc(size_t n, size_t size);

n s i z e
N U L L
<stdlib.h> mxFree
void mxSetAllocFcns(calloc_proc callocfcn,free_proc
freefcn,realloc_proc reallocfcn, malloc_proc mallocfcn);

MEX helpdesk
void mxFree(void *ptr);

ptr
void *mxRealloc(void *ptr, size_t size);

m x C a l l o c ptr size

NULL <stdlib.h>mxFree
void mxDestroyArray(mxArray *array_ptr);

array_ptrmxArray
mxArray
176 CmxArray
mxComplexity

306

MATLAB 5

m x A r r a y m x C O M P L E X(
mxArray)mxREAL()
mxClassID

mxArray
mxCELL_CLASS,
mxSTRUCT_CLASS,
mxOBJECT_CLASS,
mxCHAR_CLASS,
mxSPARSE_CLASS,
mxDOUBLE_CLASS,
mxSINGLE_CLASS,
mxINT8_CLASS,
mxUINT8_CLASS,
mxINT16_CLASS,
mxUINT16_CLASS,
mxINT32_CLASS,
mxUINT32_CLASS,
mxUNKNOWN_CLASS,

8
8
1 6
1 6
3 2
3 2

mxClassID mxGetClassID(const mxArray *array_ptr);

array_ptrmxArray
const char *mxGetClassName(const mxArray *array_ptr);

bool mxIsClass(const mxArray *array_ptr, const char *name);

a rr a y_p t rm x A r r a y n a m e n a m e
(m x C l a s s I D)c e l ls t r u c tc h a rs p a r s e
d o u b l es i n g l ei n t 8u i n t 8i n t 1 6u i n t 1 6i n t 3 2
uint32
const char *mxGetName(const mxArray *array_ptr);

a rr a y_ptrmxArray
double mxGetScalar(const mxArray *array_ptr);

a rr a y_p t rm x A r r a y d o u b l e
m x A r r a y 0 . 0 m x A r r a y
mxArray
mxArray *mxDuplicateArray(const mxArray *in);

i n m x A r r a y m x A r r a y
mxDestroyArray 175
int mxGetNumberOfElements(const mxArray *array_ptr);

a rr a y_ptrmxArray mxGetClassID
int mxGetElementSize(const mxArray *array_ptr);

a rr a y_p t rm x A r r a y m x A r r a y
0

15 MATLAB

307

int mxGetNumberOfDimensions(const mxArray *array_ptr);

a rr a y_ptrmxArray 2
const int *mxGetDimensions(const mxArray *array_ptr);

array_ptrmxArray
int mxSetDimensions(mxArray *array_ptr, const int *size, int ndims);

/ a rr a y _ p t r m x A r r a y n d i m s
s i z e
0 1 / h e l p d e s k

int mxGetM(const mxArray *array_ptr);

a rr a y_ptrmxArray
void mxSetM(mxArray *array_ptr, int m);

/array_ptrmxArraym
mxSetDimensions
int mxGetN(const mxArray *array_ptr);

array_ptrmxArray
void mxSetN(mxArray *array_ptr,int n);

/array_ptrmxArrayn
mxSetDimensions
bool mxIsEmpty(const mxArray *array_ptr);

array_ptrmxArray
bool mxIsFromGlobalWS(const mxArray *array_ptr);

a rr a y_ptrmxArrayMATLAB
bool mxIsNumeric(const mxArray *array_ptr);

array_ptrmxArray
bool mxIsInt8(const mxArray *array_ptr);

8
bool mxIsUint8(const mxArray *array_ptr);

8
bool mxIsInt16(const mxArray *array_ptr);

16
bool mxIsUint16(const mxArray *array_ptr);

16
bool mxIsInt32(const mxArray *array_ptr);

32
bool mxIsUint32(const mxArray *array_ptr);

32
bool mxIsSingle(const mxArray *array_ptr);

308

MATLAB 5

bool mxIsDouble(const mxArray *array_ptr);

bool mxIsComplex(const mxArray *array_ptr);

array_ptrmxArray
int mxCalcSingleSubscript((const mxArray *array_ptr,int nsbus,int *subs)

n s u b s a rr a y_p t r
mxArraysubs helpdesk
mn
177 C
mxArray *mxCreateDoubleMatrix(int m, int n, mxComplexity Complexflag);

m x C r e a t e C e l l M a t r i x( 1 8 1 ) mn
Complexflagm x C O M P L E X
mxREAL
double *mxGetPr(const mxArray *array_ptr);

a rr a y_ptrmxArray
NULL
void mxSetPr(mxArray *array_ptr, double *pr);

a rr a y _ p t rm x A r r a y p r
mxCalloc 175
double *mxGetPi(const mxArray *array_ptr);

mxGetPr
void mxSetPi(mxArray *array_ptr, double *pi);

mxSetPr
mn
178 C
mxArray *mxCreateSpares(int m, int n int nzmax, mxComplexity ComplexFlag);

mn nzmax
ComplexFlagm x C O M P L E Xm x R E A L

N U L L

mxDestroyArray 175
int mxGetNzmax(const mxArray *array_ptr);

a rr a y_p t r m x A r r a yn z m a x()

void mxSetNzmax(mxArray *array_ptr, int nzmax);

15 MATLAB

309

a rr a y_p t r m x A r r a yn z m a x()n z m a x
irprpi() helpdesk
int *mxGetIr(const mxArray *array_ptr);

0a rr a y_p t r
mxArray NULL
void mxSetIr(mxArray *array_ptr, int *ir);

a rr a y_p t r m x A r r a y i r
0 h e l p d e s k

int *mxGetJc(const mxArray *array_ptr);

mxGetIr helpdesk

void mxSetJc(mxArray *array_ptr, int *jc);

mxSetIrhelpdesk
bool mxIsSParse(const mxArray *array_ptr);

array_ptrmxArray
mxArrays
179 C
mxChar

mxArray
mxArray *mxCreateCharArray(int ndim, const int *dims);

mxCreateCellArray n 181
mxArray *mxCreateCharMatrixFromStrings(int m,char **str);

m x C r e a t e C e l l M a t r i x( 1 8 1 ) s t r
m
mxArray *mxCreateString(const char *str);

s t r m x A r r a y
mxArrayNULLmxArraymxDestroyArray
175
int mxGetString(const mxArray *array_ptr, char *buf, int buflen);

a rr a y_p t r m x A r r a y b u fb u f l e nb u f
0 1
bool mxIsChar(const mxArray *array_ptr);

array_ptrmxArray
M ATLAB 5 2 . 2
mxArray

310

MATLAB 5

C 8 1 6 3 2
mxArray MALTAB
180 C
mxArray *mxCreateNumericArray(int ndim, const int *dims, mxClassID class,
MxComplexity ComplexFlag);

m x C r e a t e C e l l A r r a y n c l a s s
1 7 6m x C l a s s I D C o m p l e x F l a gm x C O M P L E X
mxREAL
void *mxGetData(const mxArray *array_ptr);

m x G e t P r 1 7 7 v o i d

void mxSetData(mxArray *array_ptr ,void *data_ptr);

m x S e t P r 1 7 7 v o i d

void *mxGetImagData(const mxArray *array_ptr);

m x G e t P i 1 7 7 void

void mxSetImagData(mxArray *array_ptr, void *pi);

m x S e t P i 1 7 7 v o i d

void mxSetLogical(mxArray *array_ptr);

a rr a y_p t rm x A r r a y MATLABm x A r r a y
0
void mxClearLogical(mxArray *array_ptr);

mxArray
bool mxIsLogical(const mxArray *array_ptr);

mxArray
M ATLAB 5 5 . 5
mxArray
181 C
mxArray *mxCreateCellArray(int ndim, const int *dims);

n n d i m d i m s
NULL
mxArray *mxCreateCellMatrix(int m ,int n);

mn
mxArray *mxGetCell(const mxArray *array_ptr, int index);

mxArray a rr a y_ptr mxArrayindex

15 MATLAB

311

176mxCalcSingleSubscript
mxArrayNULL
void mxSetCell(mxArray *array_ptr, int index, mxArray *value);

m x A r r a y i n d e x
176m x C a l c S i n g l e S u b s c r i p tvalue
array_ptrmxArray
bool mxIsCell(const mxArray *array_ptr);

array_ptrmxArray
M ATLAB 5 1 2 . 5
mxArray
182 C
m x A r r a y * m x C r e a t e S t r u c t A r r a y ( inndti m , c o n s t i n t * d i m s , i n t n f i e l d s , c o n s t
char **field_names);

m x C r e a t e C e l l A r r a y ( 1 8 1 ) n
nfields field_names
m x A r r a*
ym x C r e a t e S t r u c t M a tm
r ,i xi (n i
t nn ,
t i n t n f i e l d sc,o n s tc h a r
**field_names);

mn
int mxGetNumberOfFields(const mxArray *array_ptr);

array_ptr mxArray 0
m x A r r a *y m x G e t F i e l d ( cmoxnAsrtr a *y a r r a y _ p tirn,t i n d e x ,c o n s tc h a r
*field_name);

a rr a y_ptrmxArray index
1 7 6m x C a l c S i n g l e S u b s c r i p t
field_name
NULL
void mxSetField(mxArray *array_ptr, int index, const char *field_name, mxArray
*value);

value
int mxGetFieldNumber(const mxArray *array_ptr, const char *field_name);

array_ptr mxArrayfield_name
(0)1
const c h a r * m x G e t F i e l d N a m e B y N u m b e
m x
rA
( rc ro an ys* ta r r a y _ p t r
in
,t
field_number);

a rr a y_p t r m x A r r a y f i e l d_n u m b e r
(0)
m x A r r a *y m x G e t F i e l d B y N u m b e rm (
xc
Ar
or
n as *
yt a r r a y _ p t irn,t i n d e x ,i n t
field_number);

312

MATLAB 5

m x G e t F i e l d f i e l d_n u m b e r
(0)
v o i d m x S e t F i e l d B y N u m b e r ( m x A* ra rr ar y
a y _ p t ri,n t i n d e x , i n t f i e l d _ n u m b e r ,
mxArray *value);

m x S e t F i e l d f i e l d_n u m b e r
(0)
bool mxIsStruct(const mxArray *array_ptr);

array_ptrmxArray
int mxSetClassName(mxArray *array_ptr, const char *classname);

a rr a y_p t rMATLAB c l a s s n a m e MATLAB


0 l o a d MATLAB
classname
C

183 C
double mxGetEps(void);

MATLAB
double mxGetInf(void);

MATLABinf
bool mxIsInf(double value);

value
double; mxGetNaN(void);

MATLABNaN
bool mxIsNaN(double value);

valueNaN
bool mxIsFinite(double value);

value infNaN
C
184 C
void mxAssert(int expr, char *error_message);

e x p r e x p r
expr
void mxAssertS(int expr, char *error_message);

expr expr
M ATLAB 4.2 C

15 MATLAB

313

MATLAB 5
185 C
mxCreateFull

mxIsFull

mxIsString

mxFreeMatrix

15.2.2 CMAT
M AT MATLAB

15.1
C C
M AT L A B 1 01 0
save
OldMatrix=randn(10);
save data OldMatrix;

%
% d a t a . m a t

C 2
data.matC matex.c

/**/

/**/

/*2*/

314

MATLAB 5

/**/

UNIX ( )

NewMatrix2 *OldMatrix

d a t a . m a t

M AT MATLAB
MATLABC m a t . h

#include "mat.h"

M AT

186 CMAT
MATFile

MAT
MATFile *matOpen(const char *filename, const char *mode);

m o d e f i l e n a m erw
u /w 4 MATLAB 4 MAT
MAT NULL
FILE *matGetFp(MATFile *mfp);

mfpMATC Cferror()
int matClose(MATFile *mfp);

mfpMAT 0 EOF
MAT
187 CMAT
char **matGetDir(MATFile *mfp,int *num);

m f p M AT m x A r r a y s n u m
m x A r r a y s N U L Ln u m
mxArrays mxFree 175
mxArray *matGetArray(MATFile *mfp, const char *name);

mfpMAT namemxArray

15 MATLAB

315

mxArray NULL m x D e s t r o y A r r a ymxArray


175
mxArray *matGetArrayHeader(MATFile *mfp, const char *name);

mxArray *matGetNextArray(MATFile *mfp);

mfpMATmxArraymxArray
NULLmxDestroyArray175
mxArray *matGetNextArrayHeader(MATFile *mfp);

int matPutArray(MATFile *mfp, const mxArray *mp);

m p m x A r r a y m f p M AT m x A r r a y
0
int matPutArrayAsGlobal(MATFile *mfp, const mxArray *mp);

m x A r r a y MATLAB

int matDeleteArray(MATFile *mfp, const char *name);

m f p M AT n a m em x A r r a y 0

MATLAB 4.2 MATLAB 5


C
188 CMAT

MAT
UNIX

. . . p r o g r a m n a m e
sourcecode.c C gcc
A N S I

WindowsMATLAB
mex sourcecode.c -f optfil

optfilwatengmatopts.bat(Watcom C)msvcengmatopts.bat(Microsoft
Visual C) bccengmatopts.bat(Borland C)sourcecode.cC

316

MATLAB 5

MacintoshMATLAB 5
15.2.3 CMATLAB
CMATLAB MATLAB engOpen
189
mxArrayMATLAB
1) 1mxArrayMATLAB
m x C re a t e mxSetName 15.2.1

m x A r r a y

MATLAB C
2) 2MATLABengPut189
MATLAB
engEvalString
MATLABC

15.2
C M AT L A B
C plotm.c

/**/

/*MATLAB* /
/**/
/** /

15 MATLAB

317

/**/

UNIX

15-1

15-1 C MATLAB

M AT L A B
M a c i n t o s h e n g i n e . h

#include "engine.h"

189 CMATLAB
Engine

MATLAB
Engine *engOpen(const char *startcmd);

M AT L A B s t a r t c m d
matlab MATLAB NULL
int engOutputBuffer(Engine *ep, char *p, int n);

e p MATLAB n p

int engEvalString(Engine *ep, const char *string);

epMATLAB stringMATLAB

318

MATLAB 5

0
mxArray *engGetArray(Engine *ep, const char *name);

e pMATLAB n a m em x A r r a y
m x A r r a y N U L L m x A r r a y
mxDestroyArray 175
int engPutArray(Engine *ep, const mxArray *mp);

m p m x A r r a y e p MATLAB
0 1
int engClose(Engine *ep);

epMATLAB 0 1
MATLAB 4.2 MATLAB 5
C
190 CMATLAB
MATLABC

UNIX

. . . p r o g r a m n a m e
s o u r c e c o d e . c C g c c
A N S I

WindowsMATLAB
mex sourcecode.c -f optfil

optfilwatengmatopts.bat(Watcom C)msvcengmatopts.bat(Microsoft
Visual C) bccengmatopts.bat(Borland C)sourcecode.cC

15.2.4 MATLABC
MATLABCMATLABC
M

15 MATLAB

319

M E X C MATLAB
MEX
m e x F u n c t i o n m e x F u n c t i o nMATLAB

15.3
M E X
C rmult.c
# include "mex.h"

/* */

/* MATLAB*/

/* */

/* */

320

MATLAB 5

/* * /

/* * /

UNIX ( )
/opt/matlab52/bin/mex rmult.c

MATLAB

M E X M E X
C M m e x . h

#include "mex.h"

M AT L A B C m x F u n c t i o n
M E X m e x C a l l M A T L A Bm e x E v a l S t r i n g
CMATLAB
191 CMATLAB
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]);

MATLAB n l h s p l h s
( N U L L ) n rh s p rh s
C
int mexCallMATLAB(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[],
const char *command_name);

MATLAB M M E X n l h s (
5 0 )p l h s (N U L L ) n rh s (
5 0 )p rh s c o m m a n d _ n a m e
+
0 m x D e s t r o y A r r a yplhs
mxArray 175
void mexSetTrapFlag(int trap_flag);

mexCallMATLABMATLABmexCallMATLAB

15 MATLAB

321

MEXMATLAB
trap_flag0 1MEX
int mexEvalString(const char *command);

MATLABc o m m a n d M E X c o m m a n d
0 1
int mexAtExit(void (*ExitFcn)(void));

MEX 0
m e x F u n c t i o n MATLAB

192

CMATLAB

mxArray *mexGetArray(const char *name, const char *workspace);

m x A r r a y n a m em x A r r a y w o r k s p a c e
mxArray
base MATLAB name
caller name
global name
m x A r r a y N U L L
mxDestroyArray 175
int mexPutArray(mxArray *array_ptr, const char *workspace);

m x A r r a y 0
1
const mxArray *mexGetArrayPtr(const char *name, const char *workspace);

m x A r r a y n a m e m x A r r a y
workspacemxArray(mexGetArray)NULL
mxArray
MATLAB
193 C
i n t m e x P r i n t f ( c o n s t c h a r * f o r m ar
tg,1, a r g 2, . . . ) ;

M AT L A B ANSI C f o r m a tANSI C
arg1arg2...
void mexErrMsgTxt(const char *error_msg);

MATLAB error_msg MEX


void mexWarnMsgTxt(const char *warning_msg);

MATLAB warning_msg MEX


M AT L A B C

322

MATLAB 5

14.2
194 CMEX
bool mexIsGlobal(const mxArray *array_ptr);

a rr a y_ptrmxArray
const mxArray *mexGet(double handle, const char *property);

MATLAB h a n d l e ()
p ro p e rt y m x A r r a y
NULL 14.2
int mexSet(double handle, const char *property, mxArray *value);

MATLAB v a l u e
mxArray 0114.2
void mexAddFlops(int count);

countMATLAB
M E X M E X

195 C
void mexMakeArrayPersistent(mxArray *array_ptr);

M E X m x A r r a y
M E X m x A r r a y
a rr a y_ptrmxArray
void mexMakeMemoryPersistent(void *ptr);

m x C a l l o c p t r

void mexLock(void);

MEX
void mexUnlock(void);

MEX
bool mexIsLocked(void);

MEX
MATLAB 4.2 MATLAB 5
C
196 CMEX
mexGetMatrix
mexGetFull
mexIsInf

mexGetGlobal
mexGetGlobal
mexGetNaN

mexPutMatrix
mexPutMatrix
mexIsNaN

mxGetMatrixPtr
mxGetMatrixPtr
mexIsFinite

15 MATLAB

323

MATLABC
UNIX
.../matlab52/bin/mex sourcecode.c

. . . p r o g r a m n a m e
s o u rc e c o d e . c C
MATLAB 5
WindowsMATLAB
mex sourcecode.c

MATLAB 5
M a c i n t o s h M ATLAB 5
MATLAB
Mex sourcecode.c

M E X M AT L A Bm e x e x t

M E X gU N I X
M AT L A B D d b x M AT L A B
d b m e x on MEX MEX
MATLAB d b m e x stop
c o n t i n u eMATLABWi n d o w sM a c i n t o s h M ATLAB 5

15.3 MATLABFORTRAN
F O RT R A NC M ATLAB FORT R A N

15.3.1 FORTRANmxArray
m x A r r a y m x A r r a y

C F O RT R A N
FORTRAN MATLAB4 A l p h aS G I 6 4
8 ( )
mxCopy
% v a l F O RTRAN 77F O RTRAN 90

m x G e t P rm x G e t P i 2 0 0 v a l
FORTRAN
15.6FORTRAN %val
v a l M ATLAB 5
15.6

324

MATLAB 5

197 FORTRAN
subroutine mxCopyPtrToInteger4(px, y, n)
integer*4 y(n)
integer*4 px,n

pxMATLAB n FORTRAN y
pxirjc 201mxGetIrmxGetJc
subroutine mxCopyInteger4ToPtr(y,px,n)
integer*4 y(n)
integer*4 px, n

F O RT R A N y n M ATLAB p x
pxirjc 201mxGetIrmxGetJc
subroutine mxCopyPtrToPtrArray(px, y, n)
integer*4 y(n)
integer*4 px, n

pxFORTRAN y p xi rj c
201mxGetIrmxGetJc
subroutine mxCopyPtrToReal8(px, y, n)
real*8
y(n)
integer*4
px, n

MATLABpxnFORTRAN
ypxprpi200mxGetPrmxGetPi
subroutine mxCopyReal8ToPtr(y, px, n)
real*8 y(n)
integer*4 px, n

FORTRAN yn MATLABpx
pxprpi200mxGetPrmxGetPi
subroutine mxCopyPtrToComplex16(pr, pi, y, n)
complex*16 y(n)
integer*4 pr, pi, n

p r( )p i( )MATLAB n F O RT R A N
y200mxGetPrmxGetPi
subroutine mxCopyComplex16ToPtr(y,pr,pi,n)
complex*16 y(n)
integer*4 pr,pi , n

FORTRAN yn pr()pi( )
MATLAB 200mxGetPrmxGetPi
subroutine mxCopyPtrToCharacter(px, y, n)
character*(*) y
integer*4 px, n

pxMATLABn FORTRAN y
202mxGetString
subroutine mxCopyCharacterToPtr(y, px, n)
character*(*) y

15 MATLAB

325

integer*4 px, n

FORTRAN yn pxMATLAB
202mxGetString

MATLAB MATLAB

198 FORTRAN
integer*4 function mxCalloc(n, size)
integer*4 n, size

nsize

0
mxFree
subroutine mxFree(ptr)
integer*4 ptr

ptr
subroutine mxFreeMatrix(pm)
integer*4 pm

mxCreateFullmxCreateSparsepmmxArray
199 FORTRANmxArray
character*32 function mxGetName(pm)
integer*4 pm

(32)pmmxArray0
subroutine mxSetName(pm, name)
integer*4 pm
character*(32) name

pmmxArrayname(32)
real*8 function mxGetScalar(pm)
integer*4 pm

p mm x A r r a y m x A r r a y

integer*4 function mxGetM(pm)


integer*4 pm

pmmxArray
subroutine mxSetM(pm,m)
integer*4 pm, m

pmmxArray/mxArraym
/mxArray/helpdesk
integer*4 function mxGetN(pm)

326

MATLAB 5

integer*4 pm

pmmxArray
subroutine mxSetN(pm,n)
integer*4 pm,n

p m m x A r r a y /m x A r r a y n
/mxArray/ helpdesk
integer*4 function mxIsNumeric(pm)
integer*4 pm

pmmxArray 1 0
integer*4 function mxIsDouble(pm)
integer*4 pm

p m m x A r r a y 1 0 0
mxArrayFORTRAN
integer*4 function mxIsComplex(pm)
integer*4 pm

pmmxArray 1 0
mn
200 F O RT R A N
integer*4 function mxCreateFull(m, n, ComplexFlag)
integer*4 m, n, ComplexFlag

mn( m x A r r a y )
C o m p l e x F l a g1 0 m x F r e e M a t r i x
198
integer*4 function mxGetPr(pm)
integer*4 pm

pmmxArraymxArray
0
subroutine mxSetPr(pm, pr)
integer*4 pm, pr

pmmxArray pr
mxCalloc 198
integer*4 function mxGetPi(pm)
integer*4 pm

mxGetPr
subroutine mxSetPi(pm, pi)
integer*4 pm, pi

mxSetPr
integer*4 function mxIsFull(pm)
integer*4 pm

15 MATLAB

327

pmmxArray 1 0
mn
201 FORTRAN
integer*4 function mxCreateSparse(m, n, nzmax, ComplexFlag)
integer*4 m,n,nzmax, ComplexFlag

mn nzmax
C o m p l e x F l a g10
0
integer*4 function mxGetNzmax(pm)
integer*4 pm

p m m x A r r a y n z m a x()

subroutine mxSetNzmax(pm, nzmax)


integer*4 pm, nzmax

p m m x A r r a y n z m a x() n z m a x
irprpi helpdesk
integer*4 function mxGetIr(pm)
integer*4 pm

p m
0 0
subroutine mxSetIr(pm, ir)
integer*4 pm, ir

pm ir
0helpdesk
integer*4 function mxGetJc(pm)
integer*4 pm

m x G e t I r
helpdesk
subroutine mxSetJc(pm, jc)
integer*4 pm, jc

mxSetIr helpdesk
integer*4 function mxIsSparse(pm)
integer*4 pm

pm 1 0
mxArrays
202 F O RT R A N
integer*4 function mxCreateString(str)
character*(*) str

328

MATLAB 5

s t r m x A r r a y
mxArray 0
integer*4 function mxGetString(pm, str, strlen)
integer*4 pm, strlen
character*(*) str

p m m x A r r a y FORTRAN
strstrlenstr
mxArray 0
integer*4 function mxIsString(pm)
integer*4 pm

pmmxArray 1 0

15.3.2 FORTRANMAT
MATMATLAB
15.4
FORTRAN
MATLAB 1 01 0
save
OldMatrix=randn(10);
Save data OldMatrix

%
% O l d M a t r i x d a t a . m a t

F O RT R A N 2
data.matFORTRAN matex.for

15 MATLAB

329

UNIX ( )

d a t a . m a t

NewMatrix2*OldMatrix

M AT MATLAB
MATLABFORTRANWindows
C
203 F O RT R A NMAT
integer*4 function matOpen(filename, mode)
integer*4 mfp
character*(*) filename, mode

mode filenamerwu/
w4MATLAB 4 MAT MAT
mfp0
integer*4 function matClose(mfp)
integer*4 mfp

mfpMAT 0 1
MAT
204 F O RT R A NMAT
integer*4 function matGetDir(mfp, num)
integer*4 mfp, num

330

MATLAB 5

m f p M AT m x A r r a y
nummxArray 0num
mxFree 198
integer*4 function matGetMatrix(mfp, name)
integer*4 mfp
character*(*) name

mfpMATnamemxArray mxArray
0mxFreeMatrixmxArray198
integer*4 function matGetNextMatrix(mfp)
integer*4 mfp

m f p M AT m x A r r a y m x A r r a y
0mxFreeMatrixmxArray 198
integer*4 function matPutMatrix(mfp, name)
integer*4 mp, mfp
character*(*) name

namem x A r r a ym f p M AT m x A r r a y
mxArray 0
integer*4 function matGetFull(mfp, name, m, n, pr, pi)
integer*4 mfp, m, n, pr, pi
character*(*) name

m f p M AT namemn
pr p i mnp rp i
01 m x F r e e
198
integer*4 function matPutFull(mfp, name, m, n, pr, pi)
integer*4 mfp, m, n, pr, pi
character*(*) name

namemn M AT

integer*4 function matGetString(mfp, name, str, strlen)


integer*4 mfp, strlen
character*(*) name, str

m f p M AT s t r l e n s t r 0 1
str 2str strlen3
integer*4 function matPutString(mfp, name, str)
integer*4 mfp
character*(*) name, str

s t r n a m e M AT 0
1
subroution matDeleteMatrix(mfp, name)
integer*4 mfp

15 MATLAB

331

character*(*) name

m f p M AT n a m em x A r r a y 0

MATFORTRAN
UNIX

. . . p r o g r a m n a m e
s o u r c e c o d e . f o r FORTRAN

MacintoshMATLAB 5
15.3.3 FORTRANMATLAB
F O RT R A N M AT L A B M AT L A B
engOpen 205
mxArrayMATLAB
1) 1m x A r r a yMATLAB m x C r e a t e

m x A r r a y 1 5 . 3 . 1

F O RT R A N MATLAB C m x C o p y
197
2) 2 M AT L A B e n g P u t M a t r i x
engEvalString 205
MATLAB
engEvalString

15.5
FORTRAN MATLAB
FORTRAN plotm.for

332

MATLAB 5

UNIX

15-1

M AT L A B
WindowsMacintoshC
205 F O RT R A NMATLAB
integer*4 function engOpen(startcmd)
integer*4 ep
character*(*) startcmd

MATLAB s t a rt c m d m a t l a b
MATLAB ep 0
subroutine engOutputBuffer(ep, p, n)
integer*4 ep, n
character*(*) p

epMATLAB p

15 MATLAB

333

integer*4 function engEvalString(ep, command)


integer*4 ep
character*(*) command

e pMATLAB c o m m a n dMATLAB
0
integer*4 function engGetMatrix(ep,name)
integer*4 ep
character*(*) name

e p MATLAB n a m em x A r r a y
m x A r r a y 0m x A r r a y m x D e s t r o y A r r a y
198
integer*4 function engPutMatrix(ep, mp)
integer*4 mp,ep

m p m x A r r a y e p MATLAB
mxArray 0 1
integer*4 function engGetFull(ep, name, m ,n, pr, pi)
integer*4 ep, m, n, pr, pi
character*(*) name

epMATLAB namemn
p r p i mnp rp i
0 1 m x F r e e
198
integer*4 function engPutFull(ep, name, m, n, pr, pi)
integer*4 ep, m, n, pr, pi
character*(*) name

n a m emn

integer*4ep integer*4 function engClose(ep)

epMATLAB 0 1
MATLABFORTRAN
UNIX

. . . p ro g r a m n a m e
s o u rc e c o d e . f o r F O RT R A N

15.3.4 MATLABFORTRAN
MATLABF O RT R A N M AT L A B

334

MATLAB 5

M
MEXFORTRANMATLABMEX
m e x F u n c t i o n MATLAB

15.6
M E X
FORTRAN rmult.for

15 MATLAB

335

UNIX
/opt/matlab52/bin/mexopts.sh

sol2)

( )
/opt/matlab52/bin/mex rmult.for

MATLAB

M E X M E X
FORTRAN M
MATLAB FORTRAN m e x F u n c t i o n
M E X

mexCallMATLAB

mexEvalStringFORTRANMATLAB
206 F O RT R A NMATLAB
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
integer*4 nlhs, nrhs, plhs(*), prhs(*)

MATLAB nlhs p rh s
n rh s p rh s F O RT R A N

336

MATLAB 5

integer*4 function mexCallMATLAB(nlhs, plhs, nrhs, prhs, name)


integer*4 nlhs, nrhs, plhs(*), prhs(*)
character*(*) name

MATLAB M M E X n l h s (
5 0 )p rh s n rh s (
50)p rh s name
+ 0
p rh smxArrays m x F r e e
198
integer*8 function mexCallMATLAB(nlhs, plhs, nrhs, prhs, name)
integer*4 nlhs, nrhs
integer*8 plhs(*), prhs(*)
character*(*) name

AlphaSGI64
subroutine mexSetTrapFlag(trap_flag)
integer*4 trap_flag

m e x C a l l M A T L A B M AT L A B
m e x C a l l M A T L A B M E X MATLAB
t r a p_f l a g0 1
MEX
integer*4 function mexEvalString(command)
character*(*) command

M AT L A Bc o m m a n d M E X
command 0

integer*4 function mexAtExit(ExitFcn)


subroutine ExitFcn( )

MEX 0
m e x F u n c t i o n M AT L A B

207 FORTRANMATLAB
integer*4 function mexGetMatrix(name)
character*(*) name

namemxArraymxArray
0mxArraymxFree198
integer*4 function mexGetGlobal(name)
character*(*) name

MATLAB mxArray

15 MATLAB

337

integer*4 function mexPutMatrix(mp)


integer*4 mp

m x G e t M a t r i x m x A r r a y
0 1
integer*4 function mexGetMatrixPtr(name)
character*(*) name

n a m em x A r r a y M E X
mxArraymxArray
integer*4 function mexGetFull(name, m, n, pr, pi)
integer*4 m, n, pr pi
character*(*) name

n a m emn
p r p i (mnp rp i )
0 1 m x F r e e
198
integer*4 function mexPutFull(name, m, n, pr, pi)
integer*4 m, n, pr, pi
character*(*) name

mn

FORTRAN

208 FORTRAN
real*8 function mexGetEps( )

MATLAB
real*8 function mexGetInf( )

MATLABinf
integer*4 function mexIsInf(value)
real*8 value

valueinf1 0
real*8 function mexGetNaN( )

MATLABNaN
integer*4 function mexIsNaN(value)
real*8 value

valueNaN1 0
integer*4 function mexIsFinite(value)
real*8 value

valueinfNaN1 0

338

MATLAB 5

MATLAB
209 FORTRAN
s u b r o u t i n e m e x P r i n t f ( f o r m aatr,g 1, a r g2 , . . . )
c h a r a c t e r * ( * ) f o r m a ta,r g1, a r g2 , . . .

MATLAB ANSIC formatANSIC


arg1arg2...
subroutine mexErrMsgTxt(error_msg)
character*(*) error_msg

MATLAB error_msg MEX


MATLABFORTRAN
UNIX
.../matlab52/bin/mex sourcecode.for

. . . p r o g r a m n a m e
s o u rc e c o d e . f o r F O RT R A N
MATLAB 5 15.6
WindowsMATLAB
mex sourcecode.for

M ATLAB 5
15.6
Macintosh M ATLAB 5 MATLAB

mex sourcecode.for

M E X MATLABm e x e x t

M E X gU N I X
M AT L A B D d b x M AT L A B
d b m e x on MEX MEX
MATLAB d b m e x stop
c o n t i n u e MATLABWi n d o w sM a c i n t o s h MATLAB
5

15.4 MATLAB
MATLAB
210
fullfile(dir1,

dir1, dir2, ...()

dir2,fname)

f n a m e
fnameMATLAB d i r 1, d i r 2, ...

15 MATLAB

339

UNIX/PC\
[path,name,ext,

pathnameext

ver]=fileparts(file) VMSver
filesep

MATLAB

15.7
Hadamard() 2.8 s a v e
s a v el o a d MATLAB

6464 hada.mtl

s a v e
load
MATLABfopenfclose
211
fopen(filename,op) f i l e n a m e
1 o p

r+

w+

340

MATLAB 5

a+

rw a P C
V M S o p
thelp fopen
[fp,msg]=fopen
fp 1msg
(filename,op,ark) C
arch h e l p f o p e
n

[filename,op,ark] fp filename
=fopen(fp)
oparch
fclose(fp)
fp 1 0
fclose(all)
10
15.8
(a) hada.mtl

(b) (a)

15 MATLAB

341

fwritefread
212
fwrite(fp,A,prec)

A fp
p re c 2 0
h e l p f w r i t e 4
A

fread(fp)

fp

[A,c]=fread(fp,s,prec)fpAAs
s=n

s=inf

fp

s=[m, n]

f p mn

c
feop(fp)

fp 1 0

15.9
15.7hada.mtl

MATLAB MATLAB
MATLAB
213
fprintf(fp,fstr,A,...)

fstr A

342

MATLAB 5

f p f s t r C
15-1C
help fprintf

fprintf(fstr,A,...)
[A,c]=

fp AsA

fscanf(fp,fstr,s)

s = [m, n]Afp
mn f s t r
fprinft

fgetl(fp)

fp

fgets(fp)

fp eol()

fprintffscanf5.1.2sprintfsscanf
15-1
15-1 FPRINTFSPRINTF

\n

e ,e

\r

E ,E

\b

\t

\f

\\

X ,

\a

x ,

MATLAB

[][#.#]FF15-1
15.10
(a) sprintf p

15 MATLAB

343

(b) f(x)=1/x[0, 4] tab.txt


f(x) = 1/x

Y1
Y2
tab.txt

tab.txt t y p e t a b . t x
t

(c) (b)

MATLAB

1 5 . 7
ferror
214
msg=ferror(fp)

f pI / O

[msg,errn]=ferror(fp,

344

MATLAB 5

c l e a r,

clear)

15.11

15.10(b)tab.txt

f p f s e e kf t e l lf r e w i n d

215
frewind(fp)

fp

fseek(fp,nb,u)

un b n b u

1
0
1

nb<0

ftell(fp)

u nb

nb=0

nb>0

u nb

15 MATLAB

345

15.5
M AT L A B

Lotus 1-2-3 W K 1 A S C I I
MATLAB 5.2 hdfvrml
216 /
dlmread(fname,st,r,c,v) f n a m e A S C I I
s t \ t
r c r c
(10)v=[r1, c1, r2, c2]
(r1, c1) (r2 , c2 )
(r1, c1) (r2, c2)
dlmwrite(fname,A,st,r,c) M AT L A BA A S C I I
f n a m e s t
rc r c
A(0)
wklread(fname,r,c,v)

fnameLotus 1-2-3 WK1


rcrc
(0)v[r1, c1, r2, c2]
(r1, c1)(r2, c2)(r1
c1)(r2 c2)
va1...c5sales

wklwrite(fname,A,st,r,c) MATLABA Lotus 1-2-3 WK1


f n a m e rc
rc A(0)
hdf

h d f help hdf
M AT L A B h d f
h d f
h t t p : / / h d f . n c s a . u i u c . e d u
162imreadimwrite

vrml(h,filename)

vrml 2.0 h
f i l e n a m e
.wrl
matlab.wrl

MATLABMicrosoft Wi n d o w s D D E ( )
MS Wo r dMATLAB M ATLAB Notebook
S u i t e Wo r d M AT L A B

346

MATLAB 5

MATLAB
UNIX MATLAB

MATLAB
The Signal Processing Toolbox

The Optimization Toolbox

The Symbolic Math Toolbox

Maple V

e x p o

C M
MATLAB MATLAB

A MATLAB
MATLAB
/helphelpdesk D

A.1 MATLAB
m a t l a b M AT L A B 2 . 1
MATLAB

t o u rd e m o MATLAB

M AT L A B
>>
M AT L A B
1.2
MATLAB quit
>>quit

MATLAB C T R LcMATLAB

>>

A.2
MATLAB

348

MATLAB 5

MATLAB a n s

MATLAB(2.4)

()

;MATLABq u i e t l y

MATLAB

A MATLAB

349

w h o s

MATLAB
Clear

w h o 2 . 3
4.3

l i n s p a c el o g s p a c e 4 . 3

^ 3.5
2 . 1

350

MATLAB 5

A.3
M AT L A B M AT L A B
2
1 3 . 1 A . 2
vector values
plot(vector, values)

A-1

A-1 2x

08 1 0 0 l i n s p a c e

c l f p l o t
: +
p l o t ( v e c t o r , v a l u eb
s , - .) ;

13.1 13-1
s u r fm e s h

A MATLAB

351

meshgrid13.4

[ ] ;
A-2
A - 3
surf
A-3

A-3 surf cos(x/2)sin(y/2)

A-2 2x+2y

h i s t 6 . 5 r a n d [ 0
1] rand4.1

hist A-4 stairsbar6.5

A-4

352

MATLAB 5

A.4

B*A

A*B

3.2
A det:

B t r a c en u l lo r t hi n v
7.1

Ax=bA b

MATLAB

A MATLAB

353

7.27.7
eig A

EigenVectors A EigenValues A
8.1

A.5
10.1
p=(2 1 5 17) polyval

polyder conv

p(x)=6x2+2x+5

p(x)2=4x6+4x5+21x4+78x3+59x2+170x+289
subplot13.3

354

MATLAB 5

xlabel x A-5

A-5 p(x)=2x3+x2+5x+17 p(x)2

MATLAB

p o l y f i t
1 0 . 4 4

A-6

p l o t l e g e n d
1 3 . 3
polyfitpolyval

A MATLAB

355

A-6 4

i n t e r p x= 4 . 3

h e l p i n t e r p
1
10.4

A.6
MATLAB M
M .m
draw.mMATLAB


MATLABdraw

356

MATLAB 5

A-7

A-7 Mdraw2xcosx2

d r a w. m .m
function Mdiv.m


n= rem(n, d)+y*d

MATLAB

M2.9 12.3

A.7
f m i n f m i n s
10.3

f(x) f.m

A MATLAB

357

title 13.3 grid


13.30f (x)=0xfzero
(10.2)A-82f (x)=0

A-8 fplotM

A.8
11.1 quad

sinx_x.mM sin(x)/x

q u a d(sinx_x,1 E - 8 , p i )

358

MATLAB 5

ans=
1.8520

A-9

A-9 10x10sin(x)/x

1 4 . 2 p a t c h
fplotsinx_x
f p l ot(sinx_x, [ - 1 0 1 0 ] ) ; g r i d o n ;

patch

patch x y
r
s e t (h,EdgeColor,[0 0 1]);

set get(h)14.2

A.9
xprim.mxprim

x t t

11.2MATLABode45
0t10x(0)=1(*)ode45

A MATLAB

359

[ x 1 ,t1]=ode45(x p r i m, [ 0 1 0 ] , 1 ) ;

x1t1
clf;
plot(x1,t1);

t x(0)=1 (*)
[ x 2 ,t2]=ode45(x p r i m, [ 0 1 0 ] , - 1 ) ;

hold on
hold on;
p l o t(x2,t2,:) ;
hold off;

A-10

A-10

B
MATLAB

B.1

Rn

xkyk n
Cn

p x 1, x 2, xp
p
i
1x1+ 2x 2+
+pxp=0 1=2==p=0
B.1

361

Rn

R nC n n
Cn2n

B.2
B.1R3C 3

R3 B-1

B-1

C xy (x, y)<x, y>


n

Rnxi
(x, y)=xHy
Cn ||x||2

B.6
(x, y)=0 xy
xy

362

MATLAB 5

/ 29 0

x 1, x 2, , x p
x1, x2, , x p
1

B.3
B . 2 e1, e2, e3R n(C n)
x, y, z

B.2
mnmn
23

AA iji
j ijij
nn
mn n
aii

C=A+B cij=
aij+ bij
Aaij
C=A B mn
AmpBpn

cijAiBj
ABBAABnABBA
ABBA
n nn 10IIn
A IA=AAI=A

363

n1 1n 11

x n Ann A xn

TAaij mn
AT ajinm A1
1A2 2

A A *
H

MATLABA
xy

x2 = x x
H

x Hy 1n n1

xyHnn

B.3

Ar a n k(A)A A
Amn min(m, n)
A det(A)

3) A d e t (A) = 0A

4)
5)
6)

7)
det(A)det(B)
8)
n

A=(aij)x=(x1, x2, xn) Tb=(b1, b2,bn) T

d e t (A B ) =

364

MATLAB 5

Ax=b

a1, a2,anA
det(A)0
mnA

(A)Aa1, a2,a n

(A) rank(A)
A

(A) Ax=0

mrank(A)
AT
A X = I Ann In x 1, x2,
xne1=(1, 0, 0) T, e2=(0, 1, 0) T, en=(0, 0, 1) TXI

det(A)0 AX=IXA A1,


A A1=IA1A=I

Ax=lx

(AI)x=0
A x = 0 d e t (AI)0
x k0 A k An
1, 2,n
()=det(A-I)n A ()=0
(A)=0Cayley-Hamilton
C ABB= C1A CAB AB

A(A)maxi|i|
AB

An
A x=b

det(A0

365

A1

An

An

A 0

Ax=0

=0A

B.4

AB

C=AB

C 11= A11 B11+A12B21

d e t ( A )0 A

366

MATLAB 5

det(A)=0
AH=AAH e r m i t i a n

AH=AAHermitian

AH A=A AHA
AHA= IA A1= A HA
1
x0xHAx>0Hermitian
xH Ax0
pAp=0AA2=AA
C C 1 A C A A
An

B.5
1 1
1
Givens
(i,i),(i, j), ( j, i)(j j)Givens

HouseholderI2wH w wH w=1 Hermitian

367

B.6
x2-

1-

p-

A1-

A2-

F-||A||F,

F-

368

MATLAB 5

1) A (A)||A||
2) AHermitian (A)=||A||2
3) A||A||2=1

Ax=b

b b x x
A

B.7
1) LU LU PA=LUPL 1
U
2) Cholesky A A=GGTG
3) QR

A=QRAmnQmm Rmm

4 ) An C C 1 A C = D A=
CDC1
5) A UUHAU=T A=UTUH
6) HermitianA UUHAU=DA=UTUH
7) Murnaghan-Wi n t e r s

A UUTAU=B

2211 2

A SS-1AS=JJ

8) Jordan

Jk J k= (k) J o r d a n
Jordan pAp

9)

mnA UVUTAV=Dmn

U mm, V nn D k
1 2. . . p0 pm i n (m, n) k k A
A=UDV T

369

DD+mn

mnDmnD+nmAA+ n
m A+=V D +UT

C MATLABSIMULINK
MathWorks MATLAB 5
MATLAB
M AT L A B M
MATLAB

MathWorks C - 1

C-1 http://www.mathworks.com/products/

M ATLAB 5 16 384 3
C-1 MATLAB
Prentice Hall
S I M U L I N K

C MATLABSIMULINK

371

S I M U L I N K
S I M U L I N K

what if S I M U L I N K M AT L A B
MATLABMATLAB

S I M U L I N K
C - 2 S I M U L I N K
C-3
F E M L A B

( P D E ) M AT L A B

http://www.femlab.com
S t a t e f l o w
S t a t e f l o wS I M U L I N KS I M U L I N K

MATLABdemohelpdeskMathWorks
http://www.mathworks.com/

SIMULINKStateflow
MathWorksFTP
M MathWorks
MATLABM ATLAB CC + +MathWorks
Applix LinkExcel Link MATLAB
MATLABExcel
M ATLAB Third Party pr o d u c t s M AT L A B
S I M U L I N K

C-1 MATHWORKS MATLAB


-AnalysisSynthesis

M AT L A B

Chemometrics

Communications

M AT L A B S I M U L I N K

Control System

MATLAB

Extended Symbolic Math

Maple V

372

MATLAB 5

Maple V

Financial

Frequency Domain

System Identification

Fuzzy Logic

SIMULINK

Higher-Order

Spectral Analysis
Image processing

M AT L A B

LMI Control

(LMI)

Mapping

Model Predictive Control

NAG Foundation

NAG

Neural Network

SIMULINK

Optimization

Partial Differential

Equation (PDE)

QFT Control Design

M AT L A B Q F T

Robust Control

M AT L A B

Signal Processing

Spline

Statistics

G U I ( )

Symbolic Math

Maple VMATLAB

System Identification

Wavelet

C MATLABSIMULINK

373

C-2 SIMULINK
SIMULINK

S I M U L I N K C

Real-Time Workshop

StateflowSIMULINK C

Stateflow Coder

SIMULINKSIMULINKC

C-3 SIMULINK
DSP Blockset

M AT L A BS I M U L I N K
SIMULINK

Fixed-Point Blocksets

S I M U L I N K 81 6
32

Non-linear Control

MATLABSIMULINK

Design(NCD)

SIMULINK

Power System Blockset

SIMULINK

PDE 11-111-12

D
MATLAB
expodemo

whatsnew

info

o r

Ctrl-P

Ctrl-N

Ctrl-B

Ctrl-F

Ctrl-LCtrl-

Ctrl-RCtrl-

Ctrl-AHome

DeleteBackspace

who, whos

clear

size, length

exist

pack

format

casesen

Ctrl-K

Ctrl-C

ans

cedit

pi

, 3 .141 592 6535

eps

realmax,realmin

exit, quit

MATLAB

inf

1/0

diary

NaN

0/0

save

load

i,j
1
Nargin,nargout

type,dbtype

what,dir,ls

cd

pwd

path

disp

input

ginput

pause

M a c i n t o s hWi n d o w s

help

Lookfor

User I/O

waitforbuttonpress
format

more

375

Casesen
menu

lasterr

bessel,bessely

gamma,gammaln,

gammainc
beta,betaln,betainc Beta
expint

erf,erfinv,erfc,erfcx
ellipke,ellipj

flops
tic,toc,etime
clock,date
cputime

MATLAB

cart2pol,pol2cart
cart2sph,sph2cart

computer,getenv
terminal

ver

version
MATLAB
hostid

round,fix,floor,ceil
rat

rats

rem

gcd

lcm

abs

sign

sqrt

pow2
2
exp

log,log2,log10

sin,cos,tan,cot,
sec,csc
asin,acos,atan2,
atan,acot,asec,acsc

sinh,cosh,tanh,
coth,asinh,acosh,
atanh,acoth,sech,
csch,asech,acsch

real,imag
conj
angle
unwrap
cplxpair

legendre

+
* . *, c r o s s , d o t ,
kron
/,\,./,.\
,.
^,.^
>,<,>=,<=,==,~=
&,|,~,xor

det,trace,rank

376

MATLAB 5

inv,pinv
orth,null
subspace
expm,logm,sqrtm,
funm,polyvalm
size,length
any,all,isnan,
isinf,isieee,
issparse,isstr,
isempty,finite
find

linspace,logspace
eye

ones,zeros
1
rand,randn

diag

triu,tril

fliplr,flipud,

rot90,reshape

hilb,invhilb,
toeplitz,compan,
gallery,hadamard,
hankel,magic,
pascal,rosser,
vander,wilkinson

text
strcmp

s t r t o k , s t r r e p
findstr

isstr,isletter,isspace
strmat

blanks,deblank

lower,upper,abs

ASCII

setstr,num2str,
int2str,
rats,hex2num,
hex2dec,dec2hex
sprintf,sscanf
eval,feval

sum,cumsum
prod,cumprod
diff,gradient,del2
max,min
mean,median
std
cov
corrcoef
sort
hist,bar,stairs

\
\

det,rank

inv

norm,normest

cond,condest

lu
LU
rref,rrefmovie
Echelon
chol
Cholesky
qr
QR
qrinsert,qrdelete QR
planerot
Givens

eig,polyeig
poly
trace
balance
hess
qr,qz
schur
rsf2csf

QRQZ

cdf2rdf
svd

norm
sparse

full

find

spconvert

nnz

spy

nonzeros

speye

spones
1
sprandn,sprandsym
spdiags

issparse

s p a l l o c , n z m a x
spfun

sprank

normest
2-
condest

spaugment

etree

etreeplot

colmmd,symmmd

symrcm,colperm

randperm

dmperm
Dulmage-Mendelsohn

spparms

symbfact
chollu
gplot

p o l y v a l , p o l y v a l
m

conv, deconv
residue
polyder
poly
compan
polyfit
interp1-interp6
interpft
spline
legendre,bessel,
bessely
fft,ifft
fft2,ifft2
fftshift

377

DFFT

roots
fzero
fmin,fmins

trapz,quad,quad8
ode23,ode45,ode23p

ODE

MATLAB

M M
M AT L A B .m M

MATLABend

if
if-else
1

else
else,
3
,if
end
end

fori=1:2:10
i110
1
2

378

MATLAB 5

end
while
1

end

return
pause
break
global
nargin
nargout
M
keyboard
echo
error
dbtype
dbstop,dbclear
dbstatus
dbstep,dbcont
dbup,dbdown
dbstack
dbquit

end

stem
hist,bar,stairs

Echo

plot
plot3
fplot
subplot

errorbar

comet,comet3

polar

semilogx,semilogy
loglog
quiver,feather,
compass,rose

clc

home

axis

zoom

grid

title,xlabel,ylabel,
zlabel
text

gtext

ginput

rbbox

hidden

view

viewmtx

rot90

contour

contour3

clabel

meshgrid

cylinder,sphere
surf

mesh

meshc,meshz

waterfall

surfl,surfc,

surfnorm

pcolor

fill,fill3

figure
clf
hold
subplot

slice

shading
colormap
colorbar
rgb2hsv,hsv2rgb
caxis
spinmap
brighten
contrast
whitebg
graymon

print
printopt
orient

sound
saxis
auread,auwrite
mu2lin,lin2mu
wavwrite,wavread

Sun

S u n

Windows

axes

line

text

patch

surface

image

capture

uimenu

dialog

errordlg,warndlg,
helpdlg,questdlg

movie

getframe

moviein

reset
refresh
drawnow
newplot
figure

fopen
fclose
MATLAB
fwrite
fread
fprintf
fscanf

fegtl,fgets
ferror
get

feof
set

frewind
gcf,gca,gco

fseek

ftell
clf,cla

close

delete

rotate

379

P-1 MATLAB 17 (13.613-2)


colormap pcolor subplot contrast

P-2 sphere mesh light view axis

P-3 3.75 cplxroot subplot shading faceted


()
shading interp ()

P-4 z=f(x, y) contourf z


meshgrid colormap axis

P-5
z=f(x, y) meshgrid

P-6 subplot 3D()()


pcolor hold gradient quiver
pie3 bar3 colormap caxis

P-7 MATLAB
load earth
image colormap axis

P-8 z=f(x, y)
meshgrid peaks surf colormap material light

MATLAB

MATLAB

1 MATLAB

31

2
1

32

33

34

35

MATLAB

37

38

10

39

11

40

12

41

13

42

14

43

15

44

16

17

18

19

20

21

22

36

5
45

46

47

48

49

50

51

23

52

24

53

25

54

26

27

28

29

30

6
55

56

57

58

382

MATLAB 5

59

93

60

94

61

95

62

96

63

64

97

65

98

66

10
99

67

100

68

101

69

LU

102

70

103

71

104

72

Cholesky

105

73

QR

106

74

GivensJacobi

75

76

77

78

8
79

80

81

82

83

QR

84

QZ

85

86

SVD

11
107

108

--

12 MATLAB
109

110

111

112

113

114

115

116

117

118

119

87

120

88

121

89

122

90

91

92

13
123

124

125

161

126

162

127

163

128

164

129

165

130

166

131

167

132

168

133

169

134

170

Guide

135

171

136

172

137

173

138

174

139

140

141

142

143

144

145

146

147

148

149

150

151

152

SPARC

153

Wi n d o w s

14

383

15 MATLAB
175

176

CmxArray

177

178

179

180

181

182

183

184

185

186

CMAT

187

CMAT

188

CMAT

189

CMATLAB

190

CMATLAB

154

191

CMATLAB

155

192

CMATLAB

156

193

157

194

CMEX

158

195

159

196

CMEX

160

197

FORTRAN

198

FORTRAN

384
199

MATLAB 5

F O RT R A N m x A r r a y

210

211

200

FORTRAN

212

201

FORTRAN

213

202

FORTRAN

214

203

FORTRANMAT

215

204

FORTRANMAT

216

205

FORTRANMATLAB

206

FORTRANMATLAB

207

FORTRANMATLAB

208

FORTRAN

209

FORTRAN

A MATLAB
B
C MATLABSIMULINK
D