【光學】基於matlab GUI模擬波動光光學系統【含Matlab原始碼 1064期】
阿新 • • 發佈:2021-06-27
一、簡介
基於matlab GUI模擬波動光光學系統
二、原始碼
%波動光學典型實驗的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-2021 10:08:35 % Begin initialization code - DO NOT EDIT gui_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}); end if 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 bysj2 handles.output = hObject; % Update handles structure guidata(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 structure varargout{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 slider slidervalue=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]); end function 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 double current_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 figure selection=questdlg('關閉視窗?','確定關閉','Yes','No','Yes'); switch selection case 'Yes' delete(gcf) case'No' return end % -------------------------------------------------------------------- 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 double current_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
三、執行結果
四、備註
版本:2014a
完整程式碼或代寫加1564658423