Professional Documents
Culture Documents
Matlab -
Matlab
, .
:
help, helpwin, helpdesk, demo
Matlab -
:
http://www.mathworks.com/support/
Matlab -
.
) (:
:
: ]a=[0.2,7,11,5
x=5:2:11 startNum:incNum:stopNum:
a(2)=9 :
:
]m=[2.1;66;11;9
]A=[3 4 5; 4 7 9; 2 6 7
]B=[a b;c d
)A=B(rows, cols
)A=B(3:5, 4:7
B
3
)]A=B(:,[1 3 2 4
)A=B - (transpose
]x=[5,7,9,11
name(numRows,numCol) :
zeros(3,5), rand(5,1) ones(6,2), eye (6,2)
: element wise
a.*b , a.^2 , a./b
:
sqrt(x), sin(y), exp(a+b)
result=isempty(a)% returns 1 if a is an empty array and 0 otherwise
S=sum(A) %S is a row vector of the columns sums of A
S=sum(A,2) %S is a column vector of the rows sums of A
S=sum(sum(A)) %sum of matrix A
[NumRows , NumColumns]=size(M)
( )- Sinc
a=-9:0.2:9;
[x,y] = meshgrid(a);
R = sqrt(x.^2+y.^2)+eps;
Z = sin(R)./R;
mesh(a,a,Z)
mesh(x,y,Z)
title(Sinc(sqrt(x^2+y^2)))
Matlab
path -
).Current Directory (cd
cd path .
cd d:\mydir .
) path(path,d:\mydir d:\mydir) path -
.(Matlab -
.Path browser -
workspace
whos .
save file_name
file_name.mat
load file_name
clear a a.
clear .
M-files
scripts
.
) (editor Matlab .edit
. debug
my_m_file.m script ,
.
:
- .
-
.
9
Matlab -
: pyt.m
function [c,d,e]= pyt(a,b)
% returns the hypotenuse in a right angle
% triangle according to Pythagoras theorem.
% c is the hypotenuse,
% d and e are the two sharp angles
c=sqrt(a.^2+b.^2);
d=atan(b/a);
e=pi/2-d;
10
if:
if i==1,
statement;
end
if res(n,2) ~= 0,
statement;
else
statement;
end
if (A > B),
statement;
elseif (A< B),
statement;
elseif ~A,
statement;
else
return;
end
11
switch
switch (rem(n,3) ==0) & (rem(n,2)==0)
case 0
disp('n is not dividable by 6')
case 1
disp('n is dividable by 6')
otherwise
error('This is impossible.')
end
12
for
:
for n=1:1:4,
subplot(2,2,n)
plot(a(:,1),a(:,n+1))
title(num2str(n))
end
13
while
a = 4; fa = sin(a);
b = 2; fb = sin(b);
while a - b > 5 * eps,
x = (a+b)/2; fx = sin(x);
if sign(fx) == sign(fa),
a = x; fa=fx;
break;
else
b = x; fb = fx;
end
end
14
find
| )==, < , > , (not equal) ~= ,(not) ~, (and) &, (or
) find(a==3 a
. )
( )) (x,y (
]a=[1 2 3;4 5 6;7 8 9
=a
1 2 3
4 5 6
7 8 9
) z=find(a>7
=z
6
9
) [x,y]=find(a>7
=x
3
3
=y
2
3
15
- Vectorizing loops
;x = 0:M-1
;))f = sin(x/(2*pi
;]r=[0 1 2]; c=[0 1
)[C,R]=meshgrid(c,r
=R
00
11
22
=C
01
01
01
h= R.^2 + C.^2
16
Matlab -
17
Coordinate conventions
f(x,y) sampled image, size MxN
100
f(1,1)=0, black
100
f(2,3)=100, gray
18
Matlab -
) Z=sinc(R .mesh
Z .
19
Matlab -
) Z -( )][imshow(Z,
) (x,y
).Z(x,y
20
Matlab -
Z" zoom on
" .
.
21
Manipulating images
i=imread('spine.tif');
figure;imshow(i);
figure;imshow(i,[]);
pixval
max(i(:))=63
min(i(:))=0
22
Manipulating images
i1=255-i;
figure; imshow(i1,[])
i2=i(end:-1:1,:);
figure; imshow(i2,[])
i3=i(15:143,54:207);
figure;imshow(i3,[])
23
Manipulating images
i4=i(1:10:end,1:15:end);
figure;imshow(i4,[])
r10=i(10,:);
c300=i(:,300);
figure;subplot(2,2,1);
imshow(i,[]);
subplot(2,2,2);imshow(i4,[]);
subplot(2,2,3);plot(r10,'.-');
subplot(2,2,4);plot(c300,'.-');
24
figure;imshow(i,[])
[y,x]=find(i>54);
hold on;plot(x,y,'xr')
25
Indexed ] [1-P
).(colormap
Intensity ][0-255
.
Binary 0 : 1 ,.
RGB .
.
;)% Indexed [X,map]=imread(file
;)% Intensity I=imread(pout.tif
;)imwrite(I,file.fmt, fmt
:
gray2ind,ind2gray, rgb2ind, ind2rgb, rgb2gray, im2bw
26
print -djpeg filename figure
filename.jpg
) im2double(img), im2uint8(img 8) uint8
( .double - . uint8
:
) - a=imcrop(img .
) imresize(img,[10 10],method 10X10
.
) Imrotate(img,angle,method .
27
Useful links
Matlab webinars:
http://www.mathworks.com/company/events/archived_webinars.html?record
edwebinars
28