You are on page 1of 22

MATLAB

xiezhh
MATLAB
MatlabSky
http://www.matlabsky.com

1 2010.09 No.1
MATLAB
MATLAB

Matlab | Simulink | Matlab !

http://www.matlabsky.com /cn/net/org

40 GUI
simulink
!

1
2Matlab
3
4MATLAB
5Matlab

QQ1341692017
matlabsky@gmail.com
yuthreestone@163.com
QQhttp://www.matlabsky.com/thread-3-1-1.html

http://www.matlabsky.com
http://wiki.matlabsky.com
http://blog.matlabsky.com
http://book.matlabsky.com
http://video.matlabsky.com
http://paid.matlabsky.com

1 ............................................................................................................................................1
1.1 ......................................................................................................................................................... 1
1.1.1 ............................................................................................................. 2
1.1.2 ..................................................................................................................... 2
1.2 ......................................................................................................................................................... 3
1.2.1 Matlab()............................................................................................................... 4
1.2.2 Matlab()................................................................................................................... 5
1.2.3 Matlab()................................................................................................................... 5
1.2.4 Matlab()....................................................................................................... 7
1.3 ......................................................................................................................................................... 8
1.3.1 () ............................................................................................................................................................. 8
1.3.2 ()...................................................................................................................................... 8
1.3.3 ()...................................................................................................................................... 9
1.4 ............................................................................................................................................. 9
1.4.1 ........................................................................................................ 9
1.4.2 ................................................................................................................... 9
1.5 GIF ......................................................................................................................................... 10
1.5.1 GIF ........................................................................................................ 10

2 ..........................................................................................................................................10

3 .....................................................................................................................11

4 .......................................................................................................................................14
4.1 ................................................................................................................... 14
4.2 () .................................................................................... 14
4.3 ()......................................... 15
5 MATLAB.........................................................................................16

6 MATLAB...........................................................................................................18

7 MATLAB ............................................................................................19

8 MATLAB..................................................................................................................19
MATLAB 1 1

MATLAB

Matlab
http://www.matlabsky.com/thread-592-1-1.html

Matlab

Matlab ( MATLAB
Timer MATLAB )
GUI

Matlab

1
Matlab

1.1
http://www.matlabsky.com/thread-593-1-1.html


avi Matlab

MATLAB
step1 moviein ( Matlab5.3 )

step2 getframe

getframe for

(1)F=gefframe
(2)F=gefframe(h) h
(3)F=getframe(hrect) h rec
step3 movie
movie
(1)movie(M) M
(2)movie(M,n) M n
2010 9 Matlab 2
(3)movie(M,n,fps) M fps n
step4 movie2avi avi
matlab


%
for j=1:n
%
%
%
M(j) = getframe;
end
movie(M)
%
f = getframe(gcf);
colormap(f.colormap);
image(f.cdata);

1.1.1
%by dynamic
%see also http://www.matlabsky.com
%2008.7.12

close all
figure('toolbar','none','menubar','none','NumberTitle',...
'off','name','Matlabsky');
axis equal
m=moviein(20,gcf);% 20
set(gca,'nextplot','replacechildren','box','off','color','b','xgrid','on')
title(' 20 ')
for j=1:20
plot(fft(eye(j+16)))
m(:,j)=getframe(gcf); % m
end
hh=figure('toolbar','none','menubar','none','NumberTitle',...
'off','name','Matlabsky');
title(' 5 ')
set(gca,{'xtick','ytick','xticklabel','yticklabel'},{[],[],[],[]})
movie(hh,m,5)

1.1.2
http://www.matlabsky.com/viewthread.php?tid=9489

% by xiezhh
x = linspace(-2,2,100);
[X,Y,Z] = meshgrid(x,x,x);
I1 = (X.^2+9/4*Y.^2+Z.^2-1).^3-X.^2.*Z.^3-9/80*Y.^2.*Z.^3;
p = patch(isosurface(X,Y,Z,I1,0));
set(p, 'FaceColor', 'red', 'EdgeColor', 'none');
MATLAB 1 3
view(3);
axis equal ;
axis off;
light('Posi',[0 -2 3]); % (0,-2,3)
lighting phong
set(gca,'nextplot','replacechildren');
%
XX = get(p,'XData');
YY = get(p,'YData');
ZZ = get(p,'ZData');
for j = 1:20
bili = sin(pi*j/20);
set(p,'XData',bili*XX,'YData',bili*YY,'ZData',bili*ZZ)
F(j) = getframe;
end
% 10
movie(F,10)

1.2
http://www.matlabsky.com/thread-240-1-1.html

MATLAB

Matlab

MATLAB
step1'EraseMode'
Matlab
EraseMode
none

background

Xor

step2 set xdata,ydata zdata


step3 darwnow


%
%
set(h,'erasemode',erasemode)%h line plot
%
%
%
% for while
for i=1:n
%
% MATLAB
2010 9 Matlab 4
%
set(h,'xdata',xdata,'ydta',ydata)%
drownnow%
%
% Matlab
%
end

1.2.1 Matlab ()
function f=anim_ball(K,ki)
%
%
% anim_ball(K)
% f=anim_ball(K,ki)
% K 1
% ki 1 1034
% f image(f.cdata)
%
%
%
%by dynamic
%all rights reserved by http://www.4math.cn
%2007.10.26
%
t1=(0:1000)/1000*10*pi;
x1=cos(t1);y1=sin(t1);z1=-t1;
t2=(0:10)/10;
x2=x1(end)*(1-t2);y2=y1(end)*(1-t2);z2=z1(end)*ones(size(x2));
t3=t2;
z3=(1-t3)*z1(end);x3=zeros(size(z3));y3=x3;
t4=t2;
x4=t4;y4=zeros(size(x4));z4=y4;
x=[x1 x2 x3 x4];y=[y1 y2 y3 y4];z=[z1 z2 z3 z4];
h=figure('numbertitle','off','name','()Matlabsky')
plot3(x,y,z,'b')
axis off
%
% xor
h=line('Color',[1 0 0],'Marker','.','MarkerSize',40,'EraseMode','xor');
n=length(x);
i=1;j=1;
%
while 1
if ~ishandle(h),return,end
set(h,'xdata',x(i),'ydata',y(i),'zdata',z(i));
drawnow;
pause(0.0005) %
i=i+1;
if nargin==2 & nargout==1
if(i==ki&j==1);f=getframe(gcf);end % f
end
if i>n
MATLAB 1 5
% i 1 j 1
i=1;j=j+1;
%
if j>K;break;end
end
end

1.2.2 Matlab ()
%
%by dynamic
%see also http://www.matlabsky.com
%2008.6.9
%
h=figure('numbertitle','off','name','()Matlabsky')
%
plot([-0.2;0.2],[0;0],'-k','linewidth',20);
%
g=0.98;%,
l=1;%
theta0=pi/4;%
x0=l*sin(theta0);% x
y0=-l*cos(theta0);% y
axis([-0.75,0.75,-1.25,0]);
axis off
%
% xor
head=line(x0,y0,'color','r','linestyle','.','erasemode','xor','markersize',40);
%
body=line([0;x0],[-0.05;y0],'color','b','linestyle','-','erasemode','xor');
%
t=0;%
dt=0.01;%
while 1
t=t+dt;
theta=theta0*cos(sqrt(g/l)*t);%
x=l*sin(theta);
y=-l*cos(theta);
if ~ishandle(h),return,end
set(head,'xdata',x,'ydata',y);%
set(body,'xdata',[0;x],'ydata',[-0.05;y]);
drawnow;%
end

1.2.3 Matlab ()
% M
%Matlab
%rewrite by dynamic
%more information please go to http://www.matlabsky.cn
try
close all
hfig=figure('NumberTitle','off','name',...
'Clock Animation Demo--by MatlabSky','MenuBar','none');
2010 9 Matlab 6
theta=linspace(0,6.3,1000);
x1=8*cos(theta);y1=8*sin(theta);
plot(x1,y1,'b','linewidth',1.4)%
hold on
axis equal
x2=7*cos(theta);y2=7*sin(theta);
plot(x2,y2,'y','linewidth',3.5)%
fill(0.4*cos(theta),0.4*sin(theta),'r');%
axis off
axis([-10 10 -10 10])
set(gca,'position',[[0.13 0.05 0.775 0.815]])
title(date,'fontsize',18)
for k=1:12;
xk=9*cos(-2*pi/12*k+pi/2);
yk=9*sin(-2*pi/12*k+pi/2);
plot([xk/9*8 xk/9*7],[yk/9*8 yk/9*7],'color',[0.3 0.8 0.9]);
text(xk,yk,num2str(k),'fontsize',16,'color',...
[0.9 0.3 0.8],'HorizontalAlignment','center');%
end
%
ti=clock;
th=-(ti(4)+ti(5)/60+ti(6)/3600)/12*2*pi+pi/2;
xh3=4.0*cos(th);
yh3=4.0*sin(th);
xh2=xh3/2+0.5*cos(th-pi/2);
yh2=yh3/2+0.5*sin(th-pi/2);
xh4=xh3/2-0.5*cos(th-pi/2);
yh4=yh3/2-0.5*sin(th-pi/2);
hh=fill([0 xh2 xh3 xh4 0],[0 yh2 yh3 yh4 0],[0.6 0.5 0.3]);
%
tm=-(ti(5)+ti(6)/60)/60*2*pi+pi/2;
xm3=6.0*cos(tm);
ym3=6.0*sin(tm);
xm2=xm3/2+0.5*cos(tm-pi/2);
ym2=ym3/2+0.5*sin(tm-pi/2);
xm4=xm3/2-0.5*cos(tm-pi/2);
ym4=ym3/2-0.5*sin(tm-pi/2);
hm=fill([0 xm2 xm3 xm4 0],[0 ym2 ym3 ym4 0],[0.6 0.5 0.3]);
%
ts=-(ti(6))/60*2*pi+pi/2;
hs=plot([0 7*cos(ts)],[0 7*sin(ts)],'color','w','linewidth',2);
set(gcf,'doublebuffer','on');
while 1;
ti=clock;%
%
th=-(ti(4)+ti(5)/60+ti(6)/3600)/12*2*pi+pi/2;
xh3=4.0*cos(th);
yh3=4.0*sin(th);
xh2=xh3/2+0.5*cos(th-pi/2);
yh2=yh3/2+0.5*sin(th-pi/2);
xh4=xh3/2-0.5*cos(th-pi/2);
yh4=yh3/2-0.5*sin(th-pi/2);
set(hh,'XData',[0 xh2 xh3 xh4 0],'YData',[0 yh2 yh3 yh4 0])
MATLAB 1 7
%
tm=-(ti(5)+ti(6)/60)/60*2*pi+pi/2;
xm3=6.0*cos(tm);
ym3=6.0*sin(tm);
xm2=xm3/2+0.5*cos(tm-pi/2);
ym2=ym3/2+0.5*sin(tm-pi/2);
xm4=xm3/2-0.5*cos(tm-pi/2);
ym4=ym3/2-0.5*sin(tm-pi/2);
set(hm,'XData',[0 xm2 xm3 xm4 0],'YData',[0 ym2 ym3 ym4 0])
%
ts=-(ti(6))/60*2*pi+pi/2;
set(hs,'XData',[0 7*cos(ts)],'YData',[0 7*sin(ts)])
drawnow;
pause(0.09)
end
catch
['MatlabSky-- Matlab '...
'<a href="matlab:web http://www.matlabsky.cn">http://www.matlabsky.cn</a>']
return
end

1.2.4 Matlab ()
%
%rewrite by dynamic
%more information please go to http://www.matlabsky.cn
%
figure('numbertitle','off','name',...
'Matlab Animation Demo--by matlabsky','MenuBar','none')
prompt={' v:',' L:',' r:'};
default={'5','10','2'};
v=5;L=10;r=2;
p=inputdlg(prompt,'',1,default);
v=str2double(p(1));
L=str2double(p(2));
r=str2double(p(3));
if v<=0|L<=0|r<=0
warndlg('Matlabsky ','')
else
axis([0,2*r+L,0,2*r])
ox1=r;oy1=r;ox2=r+L;oy2=r;
x1=r:0.015*v:r+L;
y1=2*r*ones(size(x1));
thita=0:0.015*v/r:pi;
x2=sin(thita)*r+ox2;
y2=cos(thita)*r+oy2;
x3=r+L:-0.015*v:r;
y3=zeros(size(x3));
x4=-sin(thita)*r+ox1;
y4=-cos(thita)*r+oy1;
x=[x1 x2 x3 x4];
y=[y1 y2 y3 y4];
plot(x,y);
2010 9 Matlab 8
text(0,-2,[' L=' num2str(L) ',' ...
' r=' num2str(r) ',' ' v=' num2str(v)]);
axis equal
set(gca,'Visible','off')
hm=line(r,2*r,'color','red','marker','.','markersize',37,'erasemode','xor');
while 1
for i=1:length(x)
try
set(hm,'xdata',x(i),'ydata',y(i));
pause(0.0003)
drawnow
catch
['MatlabSky-- Matlab '...
'<a href="matlab:web'...
'http://www.matlabsky.cn"> http://www.matlabsky.cn</a>']
return
end
end
end
end

1.3
http://www.matlabsky.com/thread-594-1-1.html

comet()

Matlab comet comet3


comet(xdata,ydata,p) % p size(x)
doc comet

step1 xy z
step2 comet comet3
1.3.1 ()
%by dynamic
%see also http://www.matlabsky.com
%2008.6.23
%
t=0:pi/50:10*pi;
x=30*sin(t);
y=30*cos(t);
z=t;
plot3(x,y,z);
hold on
%axis equal
comet3(x,y,z,0.5)

1.3.2 ()
%by dynamic
%see also http://www.matlabsky.com
MATLAB 1 9
%2008.6.23
%
vx = 40;
t = 0:0.01:10;
x = vx*t;
y = -9.8*t.^2/2;
comet(x,y)

1.3.3 ()
%by dynamic
%see also http://www.matlabsky.com
%2008.6.13
%
vx = 100*cos(1/4*pi);
vy = 100*sin(1/4*pi);
t = 0:0.001:15;
x = vx*t;
y = vy*t-9.8*t.^2/2;
comet(x,y)

1.4
http://www.matlabsky.com/thread-9255-1-1.html

MATLAB spinmap
spinmap

spinmap % 5
spinmap(t) % t
spinmap(t,inc) % t inc
spinmap('inf') % Ctrl+C

1.4.1
% by xiezhh
sphere; %
axis equal; %
axis off; %
spinmap(20,1); % 1 20

1.4.2
http://www.matlabsky.com/viewthread.php?tid=9489

% by qibbxxt
clear;clc;close all
c=5;
t=linspace(-c,c);
[x,y]=meshgrid(t);
z=17*x.^2-16*abs(x).*y+17*y.^2-225;
pcolor(x,y,z);
shading interp
2010 9 Matlab 10
pause(2);
spinmap(10)

1.5 GIF
http://www.matlabsky.com/thread-9236-1-2.html

GIF
GIF getframeframe2imrgb2ind imwrite getframe
frame2im rgb2ind imwrite
GIF imwrite GIF

1.5.1 GIF
% by xiezhh
filename = 'xiezhh.gif';
z = linspace(0, 10*pi, 100); %
x = [20*sin(z),zeros(1,10)];
y = [20*cos(z),20*ones(1,10)];
z = [z,linspace(10*pi,0,10)];
plot3(x, y, z, 'r', 'linewidth', 2); %
hold on %
h = plot3(0,20,0, '.' , 'MarkerSize' ,40, 'EraseMode' , 'xor' );
xlabel('X'); ylabel('Y'); zlabel('Z'); %
axis([-25 25 -25 25 0 40]); %
view(-210,30); %

for i = 1:length(x)
set(h, 'xdata' ,x(i), 'ydata' ,y(i), 'zdata' ,z(i));
drawnow; %
pause(0.05)
f = getframe(gcf);
imind = frame2im(f);
[imind,cm] = rgb2ind(imind,256);
if i == 1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf,'DelayTime',0.1);
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.1);
end
end

2
http://www.matlabsky.com/thread-595-1-1.html


movie
MATLAB
MATLAB MATLAB
movie2avi avi avi Matalb
MATLAB 1 11

matlab

function avimake
warning off;
load data
[M,N,K]=size(data);
data=data/(max(abs(data(:))));
aviobj = avifile('mymovie.avi','fps',10);
for kk=1:10:K
imagesc(data(:,:,kk));
set(gca,'clim',[-1 1]);
colormap(hsv(128))
frame = getframe(gca);
aviobj = addframe(aviobj,frame);
end
aviobj = close(aviobj);

gif
m(:,k)=getframe;
%%% gif ,
nn(:,:,:)=getframe;
%%()
%,()
nn1=nn.cdata;
nn1=rgb2gray(nn1);
imwrite(nn1,'out.gif','gif','WriteMode','append')

3
http://www.matlabsky.com/thread-600-1-1.html


:
:
:
:
:


1.
2: MATLAB
3: MATLAB ;
4: MATLAB
5: MATLAB
6: MATLAB


13
26 MATLAB
2010 9 Matlab 12

MATLAB

figure movie

figure figure
pause

MATLAB :
%Animationrotate peak
%by dynamic
%see also http://www.matlabsky.com
%
figure('name',' Matlabsky');
%
[X,Y,Z]=peaks(14);
surfl(X,Y,Z);
axis([-4 4 -4 4 -11 11]); %
axis off; %
shading interp;
colormap spring;
m=moviein(13); % m
for i=1:12 %
view(-37.5+30*(i-1),25);
m(:,i)=getframe; %
end
movie(m); %

%Animationrotate paraboloid
%by dynamic
%see also http://www.matlabsky.com
%
h0=figure('name',' Matlabsky');
axis([-5 10 -5 10 -10 80]) %
hold on %
%
a=0:0.5:10;
b=zeros(size(a));
c=a.^2;
theta=pi/20;
xx=a; %
yy=b; %
zz=c; %
%
for i=1:40
M=[tan(i*theta) cos(i*theta) 0;-cos(i*theta) sin(i*theta) 0;0 0 1];
temp=M*[a;b;c];
xx(i+1,:)=temp(1,:);yy(i+1,:)=temp(2,:);zz(i+1,:)=temp(3,:);
mesh(xx,zz,yy); %
axis off %
pause(0.1) % 0.1
if i==26 %
MATLAB 1 13
break
end
end

:
1Error: Missing variable or function.
Error: "End of Input" expected, ":" found.
2
3
4
5
6
7
8
9 matlab

:
,
figure

:
Matlab Matlab
MATLAB
! MATLAB
!
MATLAB MATLAB
MATLAB MATLAB
MATLAB
MATLAB
MATLAB

, MATLAB ,, MATLAB ,
!

:

MATLAB
Matlabsky MATLAB

:
1.MATLAB
2.Matlab
3.Matlabskyhttp://www.matlabsky.com
2010 9 Matlab 14

4
http://www.matlabsky.com/thread-596-1-1.html

MATLAB

MATLAB

4.1
%by dynamic
%see also http://www.matlabsky.com
%2008.6.12
%
figure('toolbar','none','NumberTitle','off','name',...
'(Rotate Peak)Matlabsky');
[X,Y,Z]=peaks(30);
surfl(X,Y,Z);
axis([-3 3 -3 3 -10 10]);
axis off;
shading interp;
colormap hot;
m=moviein(15);
for i=1:15
view(-37.5+24*(i-1),30);
m(:,i)=getframe;
end
movie(m);

4.2 ()
%by dynamic
%see also http://www.matlabsky.com
%2008.12.23
%
h=figure('numbertitle','off','name','Matlabsky');%
s1=0:.01:2*pi;
hold on;
axis equal;%
axis off;% Axes
r1=10;%
r2=3;%
w1=1;%
w2=12;%
t=0;%
pausetime=.002;%
sita1=0;
sita2=0;%
set(gcf,'doublebuffer','on') %
plot(-20,18,'color','r','marker','.','markersize',40);
text(-17,18,'');%
plot(-20,16,'color','b','marker','.','markersize',20);
MATLAB 1 15
text(-17,16,'');%
plot(-20,14,'color','w','marker','.','markersize',13);
text(-17,14,'');%
plot(0,0,'color','r','marker','.','markersize',60);%
plot(r1*cos(s1),r1*sin(s1));%
set(gca,'xlim',[-20 20],'ylim',[-20 20]);
%
p1=plot(r1*cos(sita1),r1*sin(sita1),'color','b','marker','.','markersize',30);
l1=plot(r1*cos(sita1)+r2*cos(s1),r1*sin(sita1)+r2*sin(s1));%
p2x=r1*cos(sita1)+r2*cos(sita2);
p2y=r1*sin(sita1)+r2*sin(sita2);
p2=plot(p2x,p2y,'w','marker','.','markersize',20);%
orbit=line('xdata',p2x,'ydata',p2y,'color','r');%
while 1
if ~ishandle(h),return,end
set(p1,'xdata',r1*cos(sita1),'ydata',r1*sin(sita1));%
%
set(l1,'xdata',r1*cos(sita1)+r2*cos(s1),'ydata',r1*sin(sita1)+r2*sin(s1));
ptempx=r1*cos(sita1)+r2*cos(sita2);
ptempy=r1*sin(sita1)+r2*sin(sita2);
set(p2,'xdata',ptempx,'ydata',ptempy);%
p2x=[p2x ptempx];
p2y=[p2y ptempy];
set(orbit,'xdata',p2x,'ydata',p2y);%
sita1=sita1+w1*pausetime;%
sita2=sita2+w2*pausetime;%
pause(pausetime); %
drawnow %
end

4.3 ()
%by dynamic
%see also http://www.matlabsky.com
%2008.12.6
%
clear; clc;close all

%.:
%
x0=0; y0=0; r0=80; Lmin0=0; Lmax0=0; T0=2160; w0=0*pi/T0; q0=0;
x1=0; y1=0; r1=40; Lmin1=25; Lmax1=30; T1=1080; w1=pi/T1; q1=0;
x2=0; y2=0; r2=20; Lmin2=8; Lmax2=10; T2=180; w2=pi/T2; q2=0;
x3=0; y3=0; r3=10; Lmin3=3; Lmax3=05; T3=30; w3=pi/T3; q3=0;

hh=figure('numbertitle','off','name',...
'Matlabsky');

%
sun=line(0 ,0 ,'color','r','linestyle','.','erasemode',...
'xor','markersize',r0); %
2010 9 Matlab 16
earth=line(x0,y0,'color','k','linestyle','.','erasemode',...
'xor','markersize',r1); %
moon=line(x1,y1,'color','b','linestyle','.','erasemode','xor',...
'markersize',r2); %
satellite=line(x2,y2,'color','g','linestyle','.','erasemode',...
'norm','markersize',r3); %

%
axis off
title('',...
'fontname','','fontsize',9,'FontWeight','demi','Color','black');
text(-20,50,' http://www.matlabsky.com');
text(-50,50,''); %
line(-55,50,'color','r','marker','.','markersize',80);
text(-50,40,''); %
line(-55,40,'color','k','marker','.','markersize',40);
text(-50,30,''); %
line(-55,30,'color','b','marker','.','markersize',20);
text(-50,20,''); %
line(-55,20,'color','g','marker','.','markersize',10);

%
s1=[0:.01:2*pi];
line(Lmax1*cos(s1),Lmin1*sin(s1),'linestyle',':'); %,
axis([-60,60,-60,60]); %

%
t =0;
while 1
if ~ishandle(hh),return,end
q0=t*w0; q1=t*w1; q2=t*w2; q3=t*w3; t=t+1; %
if t >= 4320; t = 0; end %
%(,,)
x0 = Lmax0 * cos(q1); y1 = Lmin0 * sin(q1);
x1 = x0 + Lmax1 * cos(q1); y1 = y0 + Lmin1 * sin(q1); %
x2 = x1 + Lmax2 * cos(q2); y2 = y1 + Lmin2 * sin(q2); %
x3 = x2 + Lmax3 * cos(q3); y3 = y2 + Lmin3 * sin(q3); %
set(sun,'xdata',x0,'ydata',y0); %
set(earth,'xdata',x1,'ydata',y1); %
set(moon,'xdata',x2,'ydata',y2); %
set(satellite,'xdata',x3,'ydata',y3); %

line('xdata',x2,'ydata',y2,'color','y'); %
line('xdata',x3,'ydata',y3,'color','r'); %

drawnow;
end

5 Matlab
http://www.matlabsky.com/thread-363-1-1.html
MATLAB 1 17

%Fraunhofer Diffraction of a Round Hole


% Matlab
%rewrite by dynamic
%all rights reserved by www.matlabsky.cn
%2008.12.3

close all
figure('numbertitle','off','name','--by Matlabsky',...
'toolbar','none','position',[217 266 694 244]);
axes('position',[0.05,0.08,0.6,0.8]);hold on;
title('Fraunhofer Diffraction of a Round Hole',...
'fontsize',14)
set(gcf,'doublebuffer','on');
axis([-4,12,-5,5]);
rectangle('position',[0,1,0.2,3],'FaceColor',[0.1,0.3,0.4]);
rectangle('position',[0,-4,0.2,3],'FaceColor',[0.1,0.3,0.4]);
rectangle('position',[3.8,-4,0.4,8],'FaceColor',...
[0.4,0.3,0.4],'Curvature',[1,1]);
rectangle('position',[11,-5,0.4,10],'FaceColor',[0.1,0.3,0.4]);
h1=plot([-4,-4],[-0.7,-0.7]);
h2=plot([-4,-4],[0,0]);
h3=plot([-4,-4],[0.7,0.7]);
for k=-4:.1:0;
pause(0.05);
try
set([h1,h2,h3],'xdata',[-4,k]);
catch
return
end
end
y=-4:.1:4;
a=linspace(-atan(4/11),atan(4/11),length(y));
a=10*sin(a);
II=abs(sinc(a)).^2*6;
x=11-II;
plot(x,y,'r')
K=find(diff(sign(diff(II)))==-2)+1;
yyN=y(K);
P=zeros(3,5); yN=[-0.7,0,0.7];H=P;
for m=1:3;
for n=1:5;
2010 9 Matlab 18
p=polyfit([0,11],[yN(m),yyN(n)],1);
P(m,n)=complex(p(1),p(2));
H(m,n)=plot(0,yN(m));
end
end
for Q=0:.1:11;
pause(0.05)
for w=1:15;
[m,n]=ind2sub([3,5],w);
Y=polyval([real(P(w)),imag(P(w))],Q);
try
set(H(w),'xdata',[0,Q],'ydata',[yN(m),Y]);
catch
return
end
end
end
axes('position',[0.65,0.08,0.3,0.8])
a=linspace(-atan(4/11),atan(4/11),300);
[X,Y]=meshgrid(a);
r=sqrt(X.^2+Y.^2);
R=10*sin(r);
II=abs(sinc(R)).^2*6;
imshow(II);
disp(['MatlabSky-- Matlab '...
'<a href="matlab:web http://www.matlabsky.cn">http://www.matlabsky.cn</a>'])

6 Matlab
http://www.matlabsky.com/thread-402-1-3.html
MATLAB 1 19

7 MATLAB
http://www.matlabsky.com/thread-571-1-1.html

8 MATLAB
http://www.matlabsky.com/thread-570-1-1.html

You might also like