function varargout = guiTestV2(varargin) % GUITESTV2 M-file for guiTestV2.fig % GUITESTV2, by itself, creates a new GUITESTV2 or raises the existing % singleton*. % % H = GUITESTV2 returns the handle to a new GUITESTV2 or the handle to % the existing singleton*. % % GUITESTV2('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GUITESTV2.M with the given input arguments. % % GUITESTV2('Property','Value',...) creates a new GUITESTV2 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before guiTestV2_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to guiTestV2_OpeningFcn via varargin. % % *See GUI Options on GUIDE's 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 guiTestV2 % Last Modified by GUIDE v2.5 28-Apr-2010 15:40:46 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @guiTestV2_OpeningFcn, ... 'gui_OutputFcn', @guiTestV2_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 guiTestV2 is made visible. function guiTestV2_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 guiTestV2 (see VARARGIN) % Choose default command line output for guiTestV2 handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes guiTestV2 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = guiTestV2_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 on selection change in targetFunc. function targetFunc_Callback(hObject, eventdata, handles) % hObject handle to targetFunc (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns targetFunc contents as cell array % contents{get(hObject,'Value')} returns selected item from targetFunc % --- Executes during object creation, after setting all properties. function targetFunc_CreateFcn(hObject, eventdata, handles) % hObject handle to targetFunc (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'); end function Amp_Callback(hObject, eventdata, handles) % hObject handle to Amp (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 Amp as text % str2double(get(hObject,'String')) returns contents of Amp as a double % --- Executes during object creation, after setting all properties. function Amp_CreateFcn(hObject, eventdata, handles) % hObject handle to Amp (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 freq_Callback(hObject, eventdata, handles) % hObject handle to freq (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 freq as text % str2double(get(hObject,'String')) returns contents of freq as a double % --- Executes during object creation, after setting all properties. function freq_CreateFcn(hObject, eventdata, handles) % hObject handle to freq (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 PhaseShift_Callback(hObject, eventdata, handles) % hObject handle to PhaseShift (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 PhaseShift as text % str2double(get(hObject,'String')) returns contents of PhaseShift as a double % --- Executes during object creation, after setting all properties. function PhaseShift_CreateFcn(hObject, eventdata, handles) % hObject handle to PhaseShift (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 pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Amp = str2double(get(handles.Amp, 'String')); Freq = str2double(get(handles.freq, 'String')); PhaseShift = str2double(get(handles.PhaseShift, 'String')); endTime = str2double(get(handles.endTime, 'String')); count = str2double(get(handles.count, 'String')); contents = cellstr(get(handles.targetFunc, 'String')); TargetFunc = contents{get(handles.targetFunc, 'Value')}; set(handles.endTime, 'enable', 'off') if (count>=0)&&(count<=3)&&(Amp~=0)&&(Freq~=0) errorCode = 1; count = count + 1; set(handles.count, 'String', count); preEqu = get(handles.dispEqu, 'String'); if strcmp(preEqu, 'Nothing') preEqu = ''; else preEqu = eval([' '' ' preEqu ' + '' ']); end reEqu = eval([''' ' preEqu '' num2str(Amp) '*' TargetFunc '(2*pi*' num2str(Freq) '*t +' num2str(PhaseShift) ') ''']); set(handles.dispEqu, 'String', reEqu); t = 0:0.01:endTime; y = subs(reEqu, 't', t, 0); plot(handles.axes1, t, y) set(handles.axes1, 'xlim', [0 endTime], 'ylim', [min(y) max(y)]*1.1, 'xgrid', 'on', 'ygrid', 'on') elseif count>3 errorCode = 2; elseif Amp==0 errorCode = 3; elseif Freq==0 errorCode = 4; end ErrorMsg = {{'Correct Expression'} {'Too many terms'} {'Amplitute is ''0'''} {'Frequency is ''0'''}}; set(handles.ErrorCode, 'String', ErrorMsg{errorCode}); function dispEqu_Callback(hObject, eventdata, handles) % hObject handle to dispEqu (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 dispEqu as text % str2double(get(hObject,'String')) returns contents of dispEqu as a double % --- Executes during object creation, after setting all properties. function dispEqu_CreateFcn(hObject, eventdata, handles) % hObject handle to dispEqu (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 endTime_Callback(hObject, eventdata, handles) % hObject handle to endTime (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 endTime as text % str2double(get(hObject,'String')) returns contents of endTime as a double % --- Executes during object creation, after setting all properties. function endTime_CreateFcn(hObject, eventdata, handles) % hObject handle to endTime (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 count_Callback(hObject, eventdata, handles) % hObject handle to count (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 count as text % str2double(get(hObject,'String')) returns contents of count as a double % --- Executes during object creation, after setting all properties. function count_CreateFcn(hObject, eventdata, handles) % hObject handle to count (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 ErrorCode_Callback(hObject, eventdata, handles) % hObject handle to ErrorCode (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 ErrorCode as text % str2double(get(hObject,'String')) returns contents of ErrorCode as a double % --- Executes during object creation, after setting all properties. function ErrorCode_CreateFcn(hObject, eventdata, handles) % hObject handle to ErrorCode (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