Вы находитесь на странице: 1из 26

C MATLAB

MATLAB

MATLAB -
. MATLAB - :
;
;
;
, ;
;
, .
MATLAB ,
, ,
,
.
,
MathCad, Maple, Mathematica MATLAB
. ,
.

(toolboxes),

.
MATLAB: , ,
, ,
, , ,
, ,
, , ,
, ,
, (Simulink), , ,
, , .
1.

, ,
, ,
, , ++
. MATLAB (MATrix
LABoratory).

23

1. MATLAB
Extended
Extended Symbolic Math Toolbox - ,
Symbolic Math

MATLAB.
Toolbox

.
Maple -
.
Maple
.
Partial Differential Equation Toolbox -
Partial
MATLAB,

Differential

Equation
.
Toolbox

,

.
Statistics
Toolbox

Spline Toolbox

Statistics Toolbox - MATLAB


.

, , ,
.
Spline Toolbox - MATLAB

.

,
,

-,

.

Curve
Fitting Curve Fitting Toolbox - MATLAB
Toolbox
,
.
,

,
.
MATLAB 2008 .
30 . .
10 40 . .
24

MATLAB

MATLAB .1.

.1.
1. Workspace
2. (Current
Directory);
3. Command Window.

Workspace (
), .
, ,
MATLAB.
, , Workspace
, , ,
. ,
(, ).
Commad Window ,
. ,
Enter.
Commad Window (
) .
, ,
, ,
.
.
Current Directory ,
, (,
25

m-).
,
, . MATLAB
,
,
,
MATLAB (
). ,
.
View
. / ,

View / Desktop Layout / Default.
ATLAB

MATLAB ,
Help / MATLAB Help.
. 2. Contents
, . Index
,
(,
MATLAB), Search
(topics) ,
, .
MATLAB ,
Demos.
Favorites
,
.

. 2. MATLAB

26

MATLAB help,
. ,
help sin .
. m-
.
help _
.
( %),
.
, m ,
, , ,
. m-
CircleSquare.m .
%
%function S = CircleSquare( R)
%R
%S
function S = CircleSquare( R)
S = pi * R^2;

MATLAB

MATLAB
:

-, MATLAB
, /++, Fortran ..
MATLAB
. ,
MATLAB .
dll MATLAB,
MATLAB.
MATLAB DDE (Dynamic
Data Exchange) ActiveX (OLE, COM) Automation.
MATLAB
MATLAB .
MATLAB
.
, MATLAB
(, ,
, .mat),
.

27

MATLAB

MATLAB
.
( )
Commad Window,
Enter.
. :
;
;
;
.

,
.
.
: , , Home, End, Ins, Backspace, Del
.
- .

. MATLAB -
. 1x1,
, , ,
. MATLAB
,
. MATLAB ,
.
, MATLAB
.
. ,
stroka.
e, ,
: 12-5 12*10^-5.
i j, 2+2i 2+2j.
.
format.
.
( :
, ).
, . ,
.
[ ] . ,
A = [1 2 3; 4 5 6] 23.
28

,
, ; .
( ) .
( ),
. , :
A(2, 3) = 100, 2- 3-
100.
: . ,
.
A = 1:10 A , 1..10 1. ..
A 110.
. ,
= [1:0.5:2] = [1.0 1.5 2.0]
.
(2:3)=[] 2- 3-
.
.
' .
.
. .
,
, ..
A = [1 2 3; 4 5 6];
B = A*A;
,
.
.* (, A = [1 2 3; 4 5 6]; B =
A.*A;)
.
.
Enter,
.
Enter
.
; .
. ,
.
,

.

end,
. , A = [ 1 2 3 4 5
6]; B = A( 2:end) = [ 2 3 4 5 6].
29

,
, help ops.

MATLAB,

.
MATLAB Fortran.

, (
) .
: A = [1 2 3; 4 5 6]; =(:),
: = [ 1; 4; 2; 3;
6].
MATLAB,
.
,
, .
. MATLAB
,
. -
, - , .
clear,
(clear all, clear global .).
MATLAB
MATLAB - ,
. ,
MATLAB .
, m-,
,
. , ,
. m-
type.

MATLAB ,
, temp Temp .
MATLAB

.
. ,
m-.
, .
m- getROI.m.
,
, (ROI region of interest,
30

).
getrect.
function B = getROI( A, rect);
rc = [ rect(1) rect(3)+rect(1) rect(2) rect(4)+rect(2)];
rect = round( rc);
B = A( rc(3):rc(4), rc(1):rc(2));

.

, MATLAB.
MATLAB

MATLAB :
MATLAB.
,
. MATLAB
MATLAB (toolboxes).
, MATLAB .

.
,
MATLAB,
, .
sqrt, sin .
. type
.
mean, , m.
MATLAB .

help.
( elfun).
, MATLAB
help elfun.
, , MATLAB
matlab\toolbox, m-,
. , matlab\toolbox\matlab
MATLAB ,
( matlab\toolbox\matlab\elfun),
( matlab\toolbox\matlab\matfun),
.
MATLAB

.
. ,
,
31

.
scen.m.
A = openIR;
viewim(A);

openIR,
, ,
viewim. (Workspace)
. scen.m
function, MATLAB.
MATLAB

m-. m-
, .
" " ( )
:
function [ RetVal1, RetVal2, ] = FunctionName( par1, par2, )
( ""
function) FunctionName,
par1, par2,, ()
() RetVal1, RetVal2
- ,
par1, par2,.., ( )
RetVal1, RetVal2, .
( FunctionName) ,
. FunctionName.m
( , -, m).
!
,
. .

.
,
( - )
.
m- MATLAB
(pseudocode)
.
clear.
. MATLAB
pcode
., ,
MATLAB , ,
.
32

m-.
m- , m-
.
(
m- m-) MATLAB.
, ().
m-
( ).
MATLAB
subfunction. m-
,
.
.
m-
(2-
) (3- ).
%
%function mn = getMeanInRect(A, rc)
%A - 3
%rc - ( getrect)
%mn -
function mn = getMeanInRect(A, rc)
numMat = size(A, 3);
nrc(1) = rc(1);
nrc(2) = rc(2);
nrc(3) = rc(1) + rc(3);
nrc(4) = rc(2) + rc(4);
for i=1:numMat
B = A( nrc(2):nrc(4), nrc(1):nrc(3), i);
mn(i) = mean(B(:));
end;

MATLAB
,
. , sin
.
,
. ,
,
, .
.


.
:
33

2
T
= 1 e H a erfc ( H a ); H = h / ,
Q/h
- , Q - , T - , h -
,
a
,

( for

):
function T = SI_STEP_NA1( time, diff, Q, cond, alf)
%function T = SI_STEP_NA1( time, diff, Q, cond, alf)
% ,
%
%time -
%diff -
%Q -
%cond -
%alf - .
colCnt = size( time, 2);
T = zeros( 1, colCnt);
H = alf / cond;
for i=1:colCnt
T(i) = Q/alf * ( 1 - exp( H^2 * diff * time(i)) * erfc( H * sqrt( diff * time( i))));
end;

,
. .*,
.
function T = SI_STEP_NA2( time, diff, Q, cond, alf)
%function T = SI_STEP_NA2( time, diff, Q, cond, alf)
% ,
%
%time -
%diff -
%Q -
%cond -
%alf - .
H = alf / cond;
T = Q/alf * ( 1 - exp( H^2 * diff * time) .* erfc( H * sqrt( diff * time)));

,
for .
, .
, zeros
, for. for
.
34

r = zeros(32,l);
for n= 1:32
r(n) = rank(magic(n));
end


MATLAB r
. ,
.

,
.
.

tic toc. tic (
clock)
TICTOC, toc ,
.
function tic
% TIC Start a stopwatch timer.
%
TIC; any stuff; TOC
% prints the time required.
% See also: TOC, CLOCK.
global TICTOC
TICTOC = clock;
function t = toc
% TOC Read the stopwatch timer.
% TOC prints the elapsed time since TIC was used.
% t = TOC; saves elapsed time in t, does not print.
% See also: TIC, ETIME.
global TICTOC
if nargout < 1
elapsed_time = etime(clock,TICTOC)
else
t = etime(clock,TICTOC);
end


Nroots.m.

function mu = NRoots( Bi, muCnt)


%function mu = NRoots( Bi, muCnt)
% muCnt
% x * tan(x) = Bi
global BiValue
BiValue = Bi;
R = zeros( 1, muCnt);
dx = 0.001;

35

a = -dx;
b = pi/2 - dx;
mu(1) = fzero( @func,[a b]);
for i=1:(muCnt-1)
a = pi/2 * (2*i - 1) + dx;
b = pi/2 * (2*i - 1) + pi - dx;
mu(i+1) = fzero(@func,[a b]);
end;
function Res = func( x)
global BiValue
Res = x * tan(x) - BiValue;

,
.
.
@. m-,
.
function plotFuncPtr( funcPtr, data)
plot( data, feval( funcPtr, data));

MATLAB

, - MATLAB
,
MATLAB. m. MATLAB
,
, ,
. ,
MATLAB
.
MATLAB,
, ++, Fortran

MATLAB.
, ,
.

MATLAB, "" MATLAB

MATLAB .
, ,
MATLAB, (DLL)
Microsoft Windows ().

/++, ,
Microsoft Visual C++.
36

MATLAB
MEX- (Matlab EXtension), MATLAB
,
. , MEX
, MATLAB

- DLL.
matlab\extern\include ,
MATLAB, -
++.
matlab\extern\examples.
, matlab\extern\src,
,
MATLAB.
External Interfaces,
MATLAB.

m-, ,
.
MATLAB .
, m-,

, MATLAB .
,
.
-
MATLAB. m- . 3.

. 3. m- .


. ,
( ).
37

, ,
.

. ,
, ..
. Debug
m-,
, ,
, .
,
, ,
, .
,
.

.


(, ,
). MATLAB
- struct ().
struct
. MyStruct1, :
data name:
MyStruct1.name = '1st result';
MyStruct1.data = [ 1, 2.5; -7.8, 2.3 ];


,
,
, .

. ,
, .
function Res = CalcFunction
comment = '';
par1 = 1;
par2 = 2;
par3 = 3;
par4 = 4;
T = OtherFunction( par1, par2, par3, par4);
Res.comment = comment;
Res.par1 = par1;
Res.par2 = par2;
Res.par3 = par3;

38

Res.par4 = par4;
Res.T = T;

, CalcFunction
OtherFunction, par1, par2, par3, par4,
par5 . ,

Res, CalcFunction. Res
,
OtherFunction .

(m- dll)
,
(Current Directory) ,
ATLAB .
, ,
, .
cd,
Current Directory
(. ). , cd C:\
.

addpath,
path.
rmpath. ,
,
.

-
MATLAB. .
. , Line
() Axes () .
Axes Figure.
Figure.
Figure.
plot, .
Figure, .
:
Root .
. MATLAB
.
Figure - , .
39

Uicontrol -
. ,
. pushbutton, radio
button slider.
Axes Figure
.
Uimenu
, Figure.
Image - ,
MATLAB,
.
Line
.
Surface - ,

XY.
Text - .
Light ,
Axes.


, handle (), MATLAB
. ,
, ,
(handle).
, ,
.
MATLAB
:
gcf (get current figure)
gca (get current axis)
gco (get current object)

, figure axes.
.
MATLAB, , (
) .
root . Figure -
, .
,
,
handle,
40

. plot
Line. surf .
/ set/get.
get( h ), h
, .
set.
: set( h, 'PropertyName', PropertyValue,...), h
, PropertyName , PropertyValue
.

plot.
X
Y. .
plot
:
hold on/ hold off /
;
axis: axis equal
, axis off
, axis([xmin xmax ymin ymax])
;
grid on/ grid off / .


surf, mesh, image, imagesc.
x y, X Y,
z, Z.
, X Y
z.
,
,
.
:
shading,
(, shading interp);
colorbar,
, ;
colormap, , ,
colormap jet jet ( MATLAB
: hsv, hot, gray, bone, copper, pink, flag,
lines, colorcube, jet, prism, cool, autumn, spring, winter, summer);
colormapeditor,
, ;
41

pixval, ,
;
getrect, getline,
,
.

1.
2.
3.
4.
5.

1.
2.
3.
4.
5.
6.


.., .. MATLAB 7. . ISBN:
5-477-00283-2. " " 2006. 464 .
.. MATLAB 7. .
.
ISBN:
5-9518-0137-0.

".
" 2006. 320 .
.. , .. , .. .
Borland C++ Builder
MATLAB. .: , 2006 496 .: ., CD.
.. MATLAB 6. . .: , 2001.
592 .
.. , .. .
Mathcad 12, MATLAB 7, Maple 9. :
. : , 2006. ,
496 .

http://www.mathworks.com - C MathWorks
MATLAB
http://matlab.exponenta.ru - MATLAB
Softline
http://www.butovo.com/~zss/matlab/5/1.htm - -
MATLAB
http://www.intuit.ru - -

http://www.citforum.ru -
http://amd.stu.neva.ru/anufriev/MLab/mlad.htm#posobie
..
. . MatLab.

42

1
1

43

44

45

2
1

46

47

.3

48

Оценить