📄 bysj2.m
字号:
%波动光学典型实验的MATLAB仿真function varargout = bysj2(varargin)% BYSJ2 M-file for bysj2.fig% BYSJ2, by itself, creates a new BYSJ2 or raises the existing% singleton*.%% H = BYSJ2 returns the handle to a new BYSJ2 or the handle to% the existing singleton*.%% BYSJ2('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in BYSJ2.M with the given input arguments.%% BYSJ2('Property','Value',...) creates a new BYSJ2 or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before bysj2_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to bysj2_OpeningFcn via varargin.%% *See GUI Options on GUIDE'sslit Tools menu. Choose "GUI allows only% one% instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help bysj2% Last Modified by GUIDE v2.5 01-Jun-2008 10:08:35% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @bysj2_OpeningFcn, ... 'gui_OutputFcn', @bysj2_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else gui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before bysj2 is made visible.function bysj2_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to bysj2 (see VARARGIN)% Choose default command line output for bysj2handles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes bysj2 wait for user response (see UIRESUME)% uiwait(handles.figure1);slidervalue=get(handles.slider1,'value');set(handles.uipanel1,'userdata',slidervalue)set(handles.edit1,'string',slidervalue*100)a=get(handles.edit2,'value');set(handles.edit2,'string',a);b=get(handles.edit5,'value');set(handles.edit5,'string',b);circular_handle=findobj('tag','circular');set(circular_handle,'userdata',0.05)body1;% --- Outputs from this function are returned to the command line.function varargout = bysj2_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.output;% --- Executes when selected object is changed in uipanel1.function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)% hObject handle to the selected object in uipanel1 % eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)body;% --- Executes on slider movement.function slider1_Callback(hObject, eventdata, handles)% hObject handle to slider1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'Value') returns position of slider% get(hObject,'Min') and get(hObject,'Max') to determine range of sliderslidervalue=get(hObject,'value');set(handles.uipanel1,'userdata',slidervalue)set(handles.edit1,'string',slidervalue*100)body1;% --- Executes during object creation, after setting all properties.function slider1_CreateFcn(hObject, eventdata, handles)% hObject handle to slider1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: slider controls usually have a light gray background.if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);endfunction edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit1 as text% str2double(get(hObject,'String')) returns contents of edit1 as a doublecurrent_str=get(hObject,'string');current_val=str2double(current_str)/100;if isnumeric(current_val)&length(current_val)==1¤t_val>=get(handles.slider1,'Min')¤t_val<=get(handles.slider1,'Max');%确认输入为数字,且在波长范围内 set(handles.slider1,'value',current_val); set(handles.uipanel1,'userdata',current_val); body1;else msgbox('请输入正确波长(380-770)','输入错误','warn');end% --- Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end% --- Executes when user attempts to close figure1.function figure1_CloseRequestFcn(hObject, eventdata, handles)% hObject handle to figure1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hint: delete(hObject) closes the figureselection=questdlg('关闭窗口?','确定关闭','Yes','No','Yes');switch selection case 'Yes' delete(gcf) case'No' returnend% --------------------------------------------------------------------function Untitled_1_Callback(hObject, eventdata, handles)% hObject handle to Untitled_1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)function edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text% str2double(get(hObject,'String')) returns contents of edit2 as a doublecurrent_str=get(hObject,'string');current_val=str2num(current_str);if isnumeric(current_val)&length(current_val)¤t_val>0;%确认输入为非零数字,且非空 set(hObject,'value',current_val); body1;else msgbox('请输入正确半径','输入错误','warn');end% --- Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)body;% --- Executes on slider movement.function slider3_Callback(hObject, eventdata, handles)% hObject handle to slider3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'Value') returns position of slider% get(hObject,'Min') and get(hObject,'Max') to determine range of sliderslidervalue=get(hObject,'value');set(handles.edit4,'string',slidervalue)body1;% --- Executes during object creation, after setting all properties.function slider3_CreateFcn(hObject, eventdata, handles)% hObject handle to slider3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: slider controls usually have a light gray background.if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);end% --- Executes on selection change in popupmenu4.function popupmenu4_Callback(hObject, eventdata, handles)% hObject handle to popupmenu4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns popupmenu4 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu4hpop_val=get(hObject,'Value');circular_handle=findobj('tag','circular'); if hpop_val==1elseif hpop_val==2 set(circular_handle,'userdata',0.05) body;elseif hpop_val==3 set(circular_handle,'userdata',0.1) body;elseif hpop_val==4 set(circular_handle,'userdata',0.5) body;end% --- Executes during object creation, after setting all properties.function popupmenu4_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction edit5_Callback(hObject, eventdata, handles)% hObject handle to edit5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit5 as text% str2double(get(hObject,'String')) returns contents of edit5 as a doublestr=get(hObject,'string');val=str2num(str);if isnumeric(val)&length(val)&all(val)==1&round(val)==val;%确认输入正确,且非空 set(hObject,'value',val); body1;else msgbox('请输入正确倍数','输入错误','warn');end% --- Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject handle to edit5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end% --------------------------------------------------------------------function Untitled_2_Callback(hObject, eventdata, handles)% hObject handle to Untitled_2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)new_f_handle= figure('Visible', 'Off');new_axes = copyobj(handles.axes1, new_f_handle);colormap(gray(255));[filename,pathname]=uiputfile({'*.jpg','JPEG文件(*.jpg)'},'保存图像');l=length(filename);if l<5 delete(new_f_handle);else file=strcat(pathname,filename); print(new_f_handle, '-djpeg100', file); delete(new_f_handle);end% --------------------------------------------------------------------function Untitled_3_Callback(hObject, eventdata, handles)% hObject handle to Untitled_3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)new_f_handle= figure('Visible', 'Off');new_axes = copyobj(handles.axes2, new_f_handle);colormap(gray(255));[filename,pathname]=uiputfile({'*.jpg','JPEG文件(*.jpg)'},'保存图像');l=length(filename);if l<5 delete(new_f_handle);else file=strcat(pathname,filename); print(new_f_handle, '-djpeg100', file); delete(new_f_handle);end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -