function varargout = GUI_01(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_01_OpeningFcn, ...
'gui_OutputFcn', @GUI_01_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function GUI_01_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = GUI_01_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
set(handles.slider1,'Value',str2num(get(hObject,'String')));
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function slider1_Callback(hObject, eventdata, handles)
set(handles.edit1,'String',num2str(get(hObject,'Value')));
function slider1_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set(hObject,'Max',760);
set(hObject,'Value',500)
set(hObject,'Min',390);
function edit2_Callback(hObject, eventdata, handles)
set(handles.slider2,'Value',str2num(get(hObject,'String')));
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function slider2_Callback(hObject, eventdata, handles)
set(handles.edit2,'String',num2str(get(hObject,'Value')));
function slider2_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set( hObject,'Max',2);
set(hObject,'value',1)
set(hObject,'Min',0);
function edit3_Callback(hObject, eventdata, handles)
set(handles.slider3,'Value',str2num(get(hObject,'String')));
function edit3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function slider3_Callback(hObject, eventdata, handles)
set(handles.edit3,'String',num2str(get(hObject,'Value')));
function slider3_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set(hObject,'Max',2);
set(hObject,'value',1);
set(hObject,'Min',0);
function pushbutton1_Callback(hObject, eventdata, handles)
lambda =1e-9*get( handles.slider1,'Value') ;
a =1e-3* get( handles.slider2,'Value') ;
f = get( handles.slider3,'Value') ;
xmax =10* lambda* f/a;
Nx =1000;
xs = linspace( -xmax,xmax,Nx) ;
Np =1000;
xpoint = linspace( -a/2,a/2,Np) ;
for i =1: Nx
sintheta = xs( i) /f;
alpha =2* pi.* xpoint* sintheta/lambda;
sumcos = sum( cos( alpha) ) ;
sumsin = sum( sin( alpha) ) ;
B( i,: ) = ( sumcos^2 + sumsin^2) /Np^2;
end
N =255;
Br = B/max( B) * N;
axes( handles.axes1),image( xmax, xs,Br) ;
axis( [ 0, 0.5,-6e-3, 6e-3]) ;
xlabel( '单缝衍射图样' )
if lambda>=622e-9 c=[ 0 0 0;1 0 0];
elseif lambda >=597e-9 c=[ 0 0 0;1 0.38 0];
elseif lambda >=577e-9 c=[ 0 0 0;1 1 0];
elseif lambda >=492e-9 c =[ 0 0 0;0 1 0];
elseif lambda >=450e-9 c =[0 0 0;0 1 1];
elseif lambda >=435e-9 c =[ 0 0 0;0 0 1];
else c =[0 0 0;0.5 0 0.5];
end
colormap(c) ;
axes(handles.axes2) ;
plot( B, xs,'b.-') ,grid on;
axis( [0,1,-6e-3,6e-3]) ;
xlabel( '单缝衍射光强分布' )