function varargout = gui05(varargin) % GUI05 MATLAB code for gui05.fig % GUI05, by itself, creates a new GUI05 or raises the existing % singleton*. % % H = GUI05 returns the handle to a new GUI05 or the handle to % the existing singleton*. % % GUI05('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GUI05.M with the given input arguments. % % GUI05('Property','Value',...) creates a new GUI05 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before gui05_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to gui05_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 gui05 % Last Modified by GUIDE v2.5 06-Jul-2016 20:09:28 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @gui05_OpeningFcn, ... 'gui_OutputFcn', @gui05_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 gui05 is made visible. function gui05_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 gui05 (see VARARGIN) % Choose default command line output for gui05 handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes gui05 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = gui05_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; 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 % --- 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 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 % --- 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 % --- Executes on button press in togglebutton1. function togglebutton1_Callback(hObject, eventdata, handles) % hObject handle to togglebutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of togglebutton1 % ------ START USER-PROGRAMMED CODE ------------- % this is an example simulation of an process stepping in time, % e.g., solution of a set of ordinary differential equations % (an initial value problem), by the Euler method % get state of this toggle button tTog = get(hObject,'Value'); if tTog % put the string 'on' into the field text1 set(handles.text1,'String','on') tCount = 0; tPlotArray = 0.5 + zeros(100); plot(tPlotArray) % default plot to axes1 % repeat stepping simulation and updating display while tTog % call user-defined function fUpdateState % to update state of simulation % in this example, state is just a counter value tCount = fUpdateState(tCount,hObject, eventdata, handles); % call user-defined function fDisplayState to display % new state of simulation % here pass state tPlotArray & tCount via argument % but could get/set values in hidden field, or possibly % another way yet to be discovered... tPlotArray = fDisplayState(tPlotArray,tCount,hObject, eventdata, handles); % check state of on/off button % to see if want to stop repeat tTog = get(hObject,'Value'); end % final display when stop % put the string 'off' into the field text1 set(handles.text1,'String','off'); % get the string in the field text2 tStr = get(handles.text2,'String'); % add (concatenate) string ' STOPPED' to end tStr = strcat(tStr,' STOPPED'); % put the new string into the field text2 set(handles.text2,'String',tStr); end function tCountNew = fUpdateState(tCount,hObject, eventdata, handles) % THIS FUNCTION UPDATES THE STATE OF THE SIMULATION % USE A REPEAT HERE TO TAKE MORE THAN ONE STEP BETWEEN DISPLAYS % input argument is old counter value % update user-entered input params % get the character string in the field edit1 tStep = get(handles.edit1,'String'); % update the state of the sim % here the sim is just a counter tStep = 0.1 * str2double(tStep); tCountNew = tCount + tStep; function tNewArray = fDisplayState(tPlotArray,tCount,hObject, eventdata, handles) % THIS FUNCTION DISPLAYS THE STATE OF THE SIMULATION % input arguments here are old plot array and counter value % convert new value of tCount to a string tStr = num2str(tCount); % put the string into field text2 set(handles.text2,'String',tStr); % as example, we will plot sin of the counter % since doing calculations here, this could be in fUpdateState() tSin = sin(tCount); % change color of the panel tNewColor = 0.5 + 0.5 * tSin; % 0-1 set(handles.uipanel1,'BackgroundColor',[tNewColor 0 1-tNewColor]); % get amplitude from slider1 tAmp = get(handles.slider1,'Value'); % change height of the panel by changing Position % height can't be set directly % changing Position also allows objects to be moved tHt = 1 + 17 * tAmp * (0.5 + 0.5 * tSin); % need > 0 tPos = get(handles.uipanel1,'Position'); tPos(4) = tHt; set(handles.uipanel1,'Position',tPos); % update plot array by dropping first point and adding % new value at end tLen = length(tPlotArray); tNewArray = tPlotArray(2:tLen); tNewPt = 0.5 + 0.5 * tAmp * tSin; % 0-1 tNewArray = [tNewArray tNewPt]; % default plot to axes1 plot(tNewArray) axis([0 tLen 0 1]) % need pause to slow sim so can see display changing in app pause(0.1)