Professional Documents
Culture Documents
------------------------------------------------------------
-------------------------------------------------------
-------------------------------------
-------------------------------------------
----------------------------------------------
------------------------------------------------------
-----------------------------------------------------
------------------------------------------------------
---------------------------------------------------
---------------------------------------------------
------------------------------
--------------------------------------------
---------------------------------------
-------------------------------------------------
--------------------------------------------------
---------------------------------------------
-----------------------------------
------------------------------------
-----------------------------------
--------------------------------------
----------------------------------
- --------------------------------
-------------------------------------
--------------------------------------------
---------------------------------------
--------------------------------------------------
-----------------------------------------------------
------------------------------------------------------
---------------------------------------
---------------------------------------------
---------------------------------------------------------
-------------------------------------------------
-----------------------------
-----------------------------------
-------------------------------------------------
----------------------------------------------------------
----------------------------------------------------------
------------------------------------------
----------------------------------------------------------
------------------------------------------------
------------------------------------------------
---------------------------------------------------
--------------------------------------------
-----------------------------------------------------
---------------------------------------------
-----------------------------------------
---------------------------------------------
------------------------------
------------------------------------------
---------------------------------------------
-----------------------------------
.........................................................................................
..........................................................................................
......................................................................................
.........................................................................................
..........................................................................................
.................................................................................
........................................................................................
..................................................................................................
..........................................................................................
....................................................................................
...................................................................................
.....................................................................................
........................................................................................
.........................................................................................
........................................................................................
.........................................................................................
.........................................................................................
........................................................................................
...................................................................................
.................................................................................
........................................................................................
...........................................................
---------------------------------------------
------------------------------
-----------------------------------------
-------------------------------------------------- : if
-------------------------------------------------
--------------------------------------------- for
-------------------------- enter
-------------------------------- 10s
------------------------------------------------- while
----------------------------------------------------- fprintf
----------------------------------------------- menu
------------------------------------------------------ switch
--------------------------------------------------------
...............................................................................................
.............................................................................................
----------------------------------------------------
- -------------------------------- R
-------------------
------- im2bw()
------------- mat2gray()
------------------ imread(),imwrite()
---------------------------------------------------
............................................................. imresize()
........................................................................
............................................. imrotate()
.............................................. imcrop
------------------------
....................................... 3x3
-----------------------------------------------------
............................ conv2()
............................................................................................... imfilter()
......................... fspecial()
..... ftrans2()
....................................................................................
................................................ FIR
-----------------------------------
-------------------------------------------------------
------------------------------------------
---------------------------------------------
-------------------------------------------------
-----------------------------------------------------
mfile
Help
salehijun@gmail.com
Learning MATLAB
a =
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
a(4:-1:1,:)
ans =
16 17 18 19 20
11 12 13 14 15
6 7 8 9 10
1 2 3 4 5
a(:,5:-1:1)
ans =
5 4 3 2 1
10 9 8 7 6
15 14 13 12 11
20 19 18 17 16
f=[1,2,3,...
4,5,6]
f =
1 2 3 4 5 6
size(a)
ans =
4 5
a =
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
[L,C]=size(a)
L =
4
C =
5
eye(2)
ans =
1 0
0 1
eye(3)
ans =
1 0 0
0 1 0
0 0 1
eye(4)
ans =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
eye(2,3)
ans =
1 0 0
0 1 0
eye(4,3)
ans =
1 0 0
0 1 0
0 0 1
0 0 0
zeros(3)
ans =
0 0 0
0 0 0
0 0 0
zeros(2,3)
ans =
0 0 0
0 0 0
ones(3)
ans =
1 1 1
1 1 1
1 1 1
ones(2,3)
ans =
1 1 1
1 1 1
rand(3)
ans =
0.9501 0.4860 0.4565
0.2311 0.8913 0.0185
0.6068 0.7621 0.8214
rand(2,3)
ans =
0.4447 0.7919 0.7382
0.6154 0.9218 0.1763
magic(3)
ans =
8 1 6
3 5 7
4 9 2
magic(4)*ones(4)
ans =
34 34 34 34
34 34 34 34
34 34 34 34
34 34 34 34
inv(a)
e=[1 2 3
4 5 6
7 8 9]
e =
1 2 3
4 5 6
7 8 9
inv(e)
ans =
1.0e+016 *
-0.4504 0.9007 -0.4504
0.9007 -1.8014 0.9007
-0.4504 0.9007 -0.4504
e^(-1)
ans =
1.0e+016 *
-0.4504 0.9007 -0.4504
0.9007 -1.8014 0.9007
-0.4504 0.9007 -0.4504
det(e)
ans =
0
e'
ans =
1 4 7
2 5 8
3 6 9
e =
1 2 3
4 5 6
7 8 9
f=[1 1+2*i
2 2+3*i]
f =
1.0000 1.0000 + 2.0000i
2.0000 2.0000 + 3.0000i
f'
ans =
1.0000 2.0000
1.0000 - 2.0000i 2.0000 - 3.0000i
f.'
ans =
1.0000 2.0000
1.0000 + 2.0000i 2.0000 + 3.0000i
trace(c)
ans =
40
c =
1 2 3 4
6 7 8 9
11 12 13 14
16 17 18 19
tril(c)
ans =
1 0 0 0
6 7 0 0
11 12 13 0
16 17 18 19
c =
1 2 3 4
6 7 8 9
11 12 13 14
16 17 18 19
triu(c)
ans =
1 2 3 4
0 7 8 9
0 0 13 14
0 0 0 19
diag(c)
ans =
1
7
13
19
diag(ans)
ans =
1 0 0 0
0 7 0 0
0 0 13 0
0 0 0 19
help inf
INF Infinity.
INF returns the IEEE arithmetic representation for positive
infinity. Infinity is also produced by operations like
dividing by
zero, eg. 1.0/0.0, or from overflow, eg. exp(1000).
INF('double') is the same as INF with no inputs.
INF('single') is the single precision representation of
INF.
INF(N) is an N-by-N matrix of INFs.
INF(M,N) or INF([M,N]) is an M-by-N matrix of INFs.
INF(M,N,P,...) or INF([M,N,P,...]) is an M-by-N-by-P-by-...
array of INFs.
INF(...,CLASSNAME) is an array of INFs of class specified
by CLASSNAME.
CLASSNAME must be either 'single' or 'double'.
See also Na<a href="matlab:help n">n</a>, <a
href="matlab:help isinf">isinf</a>, <a
href="matlab:help isfinite">isfinite</a>, <a
href="matlab:help isfloat">isfloat</a>.
Reference page in Help browser
<a href="matlab:doc inf">doc inf</a>
format short
1/3
ans =
0.3333
format long
1/3
ans =
0.33333333333333
format bank
1/3
ans =
0.33
format
1/3
ans =
0.3333
format hex
pi
ans =
400921fb54442d18
format rat
pi
ans =
355/113
format +
22
ans =
+
-22
ans =
-
ans =
triu(c)*tril(c)
diary
abs(-1.2)
ans =
1.2000
a=[-1.2 2]
a =
-1.2000 2.0000
abs(a)
ans =
1.2000 2.0000
b=[-1.2 1.2-2*i]
b =
-1.2000 1.2000 - 2.0000i
abs(b)
ans =
1.2000 2.3324
ceil(1.2)
ans =
2
ceil(-1.2)
ans =
-1
floor(1.2)
ans =
1
floor(-1.2)
ans =
-2
round(1.2)
ans =
1
round(1.8)
ans =
2
round(-1.8)
ans =
-2
round(-1.2)
ans =
-1
fix(1.8)
ans =
1
fix(-1.8)
ans =
-1
sqrt(2)
ans =
1.4142
sqrt(4)
ans =
2
c=2-4i
c =
2.0000 - 4.0000i
angle(c)
ans =
-1.1071
d=1+i
d =
1.0000 + 1.0000i
angle(d)
ans =
0.7854
ans*180/pi
ans =
45
real(d)
ans =
1
imag(d)
ans =
1
d =
1.0000 + 1.0000i
complex(2,6)
ans =
2.0000 + 6.0000i
conj(1+2*i)
ans =
1.0000 - 2.0000i
gcd(12,3)
ans =
3
gcd(5,3)
ans =
1
lcm(12,3)
ans =
12
lcm(5,3)
ans =
15
sign(1-(2*3)+4)
ans =
-1
sign(-11)
ans =
-1
sign(11)
ans =
1
sign(0)
ans =
0
sign(10000)
ans =
1
log(2)
ans =
0.6931
log10(1000)
ans =
3
log2(8)
ans =
3
mod(5,2)
ans =
1
nchoosek(5,3)
ans =
10
a=pi/2
a =
1.5708
sin(a)
ans =
1
cos(a)
ans =
6.1232e-017
tan(a)
ans =
1.6331e+016
cot(a)
ans =
6.1232e-017
asin(a)
ans =
1.5708 - 1.0232i
acos(a)
ans =
0 + 1.0232i
atan(a)
ans =
1.0039
acot(a)
ans =
0.5669
asinh(a)
ans =
1.2334
acosh(a)
ans =
1.0232
atanh(a)
ans =
0.7525 + 1.5708i
acoth(a)
ans =
0.7525
sec(a)
ans =
1.6331e+016
csc(a)
ans =
1
sech(a)
ans =
0.3985
csch(a)
ans =
0.4345
x=0:0.1:pi/2;
y=sin(x);
plot(x,y)
z=cos(x);
plot(x,y)
hold on
plot(x,z)
hold off
figure(2)
salam='salam mahdi'
salam =
salam mahdi
salam
salam =
salam mahdi
a='salam'
a =
salam
a =
salam
axis([1 2 0 1])
axis([1 2 0 1 5 6])
plot(x,y)
grid
plot(x,y,'r')
plot(x,y,'b')
plot(x,y,'k')
plot(x,y,'g')
plot(x,y,'y')
plot(x,y,'c')
plot(x,y,'w')
plot(x,y,'m')
plot(x,y,'-')
plot(x,y,'--')
plot(x,y,'-.')
plot(x,y,':')
plot(x,y,'*')
plot(x,y,'o')
plot(x,y,'^')
plot(x,y,'d')
plot(x,y,'s')
plot(x,y,'v')
plot(x,y,'p')
plot(x,y,'h')
plot(x,y,'x')
plot(x,y,'-.rs')
plot(x,y,'-.sr')
plot(x,y,'linewidth',2,'markersize',12,'markerfacecolor','r','markered
gecolor', [0.4 0.2 0.3])
plot(x,y,'s','linewidth',2,'markersize',12,'markerfacecolor','r',
'markeredgecolor',[0.4 0.2 0.3])
Linewidth :
Markersize :
Markerfacecolor :
Markeredgecolor :
x=[1:0.1:5];
y=sin(x);
plot(x,y,'sr' ,'linewidth',2,'markersize',12,'markerfacecolor',[0.4 1
0.6]);xlabel('x axis'); ylabel('y axis');
subplot(2,3,1);plot(x,y,'sr','linewidth',2,'markersize',12,'markerface
color',[0.4 1 0.6]);xlabel('x axis');ylabel('y
axis');title('rasm');text(2,0,'(2,0)');
plot(x,y,'sr' ,'linewidth',2,'markersize',12,'markerfacecolor',[0.4 1
0.6]);grid;xlabel ('x axis');ylabel('y axis');title('rasm'
);text(2,0,'(2,0)');
teta=0:.1:2*pi;
c=1-2*sin(teta);
polar(teta,c);
semilogx(x,y);
semilogy(x,y);
loglog(x,y);
comet(x,y);
bar(x,y);
barh(x,y);
hist(y,x);
x=-pi:.1:pi;
bar(x,exp(x.^2));
hist(y,x)
stairs(x,y);
stem(x,y);
pie(x)
a=[1 3 4 2];
b=[1 0 0 1];
pie(a,b)
c=[1 0 0 9];
pie(a,c)
t=0:0.1:2*pi;
x=sin(t);
y=cos(t);
plot3(x,y,t)
[x y]=meshgrid(0:.1:10,0:3);
z=peaks(x,y);
mesh(x,y,z)
meshz(x,y,z)
meshc(x,y,z)
surf(x,y,z)
[x,y,z]=cylinder(2+cos(t))
surf(x,y,z)
fplot('sin',[-pi 2*pi])
c=[1 0 9;1 3 9;2 5 7];
det(c)
ans =
-33
syms x
int(1/(1+x^2))
ans =
atan(x)
syms x y
int(y/(1+x),x)
ans =
y*log(1+x)
int(y/(1+x),x,0,1)
ans =
y*log(2)
diary
mfile
help
X=input('please enter a number for X')
: if
If(a~=b)|(a==b)
disp('this is an example')
end
~=
'elseif','else'
for
For i=1:2:50
..
.
End
mfile mfile go to
/n _
n
enter
pause
10s
pause(10)
while
While i=0
.
.
i=i+1
end
fprintf
decimal D
fix point F
%6.2
break return
menu
mfile
mfile
switch
stat.m stat.m
f = sym('2*x')
int(f)
int(f,1,2)
whos R
Image Show
imshow(R)
I BW
Imshow() Imview()
im2bw()
v BW
mat2gray()
m=magic(100);
g=mat2gray(m);
imshow(g)
imread(),imwrite()
imresize()
imrotate()
r ro
imcrop
v c
r= imread ( 'tire.tif' );
f= inline ( 'max(x(:))' );
r2= nlfilter ( r,[3 3],f );
imshow(r2)
figure
imshow(r)
r r2
conv2()
i=magic(1000);
f=magic(10);
c=conv2(i,f);
whos i f c
mesh(c)
imfilter()
r r2
fspecial()
r r2
ftrans2()
colormap(jet(64))
b = remez(10,[0 0.05 0.15 0.55 0.65 1],[0 0 1 1 0 0]);
[H,w] = freqz(b,1,128,'whole');
plot(w/pi-1,fftshift(abs(H)))
mx3 colormap()
blue green red
RGB
m remez()
H b freqz()
H
128x1
2 Whole
fftshift()
plot(w/pi-1,fftshift(abs(H)))
hold on
plot(w,(abs(H)), r )
h = ftrans2(b);
freqz2(h)
b ftrans2()
f2 f1 64x1 H 64x64 freqz2()
f2 f1 H
hd=zeros(11,11);
hd(4:8,4:8)=1;
[f1,f2]=freqspace(11,'meshgrid');
f2 f1 11x11 freqspace()
f2 f1
[f1,f2]=freqspace(11);
f2 f1
F1=f2=[-n:2:n-2]/n
f1=f2=[-n+1:2:n-1]/n
meshgrid
mesh(f1,f2,hd)
f2 f1 hd z hd y f2 x f1 mesh()
hd
hd
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1 0 0 0
0 0 0 1 1 1 1 1 0 0 0
0 0 0 1 1 1 1 1 0 0 0
0 0 0 1 1 1 1 1 0 0 0
0 0 0 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
h=fsamp2(hd);
h hd FIR fsamp2()
mesh() hd
FIR filter
FIR h
32x32
freqz2(h,[32 32])
FIR filter
FIR
h=fwind1(hd,hamming(11))
n hamming(n)
hd FIR fwind1()
hd
freqz2(h,[32 32])
FIR
11x11
FIR filter
0 0 0 0 0 0.0025 0 0 0 0 0
0 0 0.0005 -0.0003 -0.0027 -0.0041 -0.0027 -0.0003 0.0005 0 0
0 0.0005 0.0018 -0.0013 -0.0126 -0.0198 -0.0126 -0.0013 0.0018 0.0005 0
0 -0.0003 -0.0013 0.0010 0.0093 0.0147 0.0093 0.0010 -0.0013 -0.0003 0
0 -0.0027 -0.0126 0.0093 0.0833 0.1324 0.0833 0.0093 -0.0126 -0.0027 0
0.0025 -0.0041 -0.0198 0.0147 0.1324 0.2066 0.1324 0.0147 -0.0198 -0.0041 0.0025
0 -0.0027 -0.0126 0.0093 0.0833 0.1324 0.0833 0.0093 -0.0126 -0.0027 0
0 -0.0003 -0.0013 0.0010 0.0093 0.0147 0.0093 0.0010 -0.0013 -0.0003 0
0 0.0005 0.0018 -0.0013 -0.0126 -0.0198 -0.0126 -0.0013 0.0018 0.0005 0
0 0 0.0005 -0.0003 -0.0027 -0.0041 -0.0027 -0.0003 0.0005 0 0
0 0 0 0 0 0.0025 0 0 0 0 0
h=[ ];
Freqz2(h)
1x3
RGB
y x R,G,B
z
Help
+12 -12
Max232
1200 COM1
ser=serial('COM1','BaudRate',1200)
1
fopen(ser);
fwrite(ser,'B')
fclose(ser);
delete(ser);
clear ser;
usb
IMAQHWINFO(2)
vid=videoinput('winvideo',2,'RGB24_160x120');
160x120 R,G,B RGB24
preview(vid)
for i=1:200
I=getsnapshot(vid);
End
vid=videoinput('winvideo',2,'RGB24_160x120');
preview(vid)
I=getsnapshot(vid);
a=I(1:15,5:20);
fa=mean(mean(a));
clear;
colorimg=imread('white lines.bmp'); %load color image.
imshow(colorimg);
title('original image');
pause;
%dissect image
for a=1:1:170 %ys
for b=1:1:228 %x s
%must cast intensities from uint8 to uint16 since they will
%overflow 2^8 limit when added together
red=cast(colorimg(a,b,1),'uint16'); %get red intensity
green=cast(colorimg(a,b,2),'uint16'); %get green intensity
blue=cast(colorimg(a,b,3),'uint16'); %get blue intensity
%redPHOTO
for a=1:l
for b=1:c
rphoto(a,b,1)=i(a,b,1);
rphoto(a,b,2)=0;
rphoto(a,b,3)=0;
end
end
%greenPHOTO
for a=1:l
for b=1:c
gphoto(a,b,1)=0;
gphoto(a,b,2)=i(a,b,2)/255;
gphoto(a,b,3)=0;
end
end
%bluePHOTO
for a=1:l
for b=1:c
bphoto(a,b,1)=0;
bphoto(a,b,2)=0;
bphoto(a,b,3)=i(a,b,3)/255;
end
end
imshow(rphoto)
figure
imshow(gphoto)
figure
imshow(bphoto)