function varargout = Matlab555(varargin) % MATLAB555 M-file for Matlab555.fig % MATLAB555, by itself, creates a new MATLAB555 or raises the existing % singleton*. % % H = MATLAB555 returns the handle to a new MATLAB555 or the handle to % the existing singleton*. % % MATLAB555('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in MATLAB555.M with the given input arguments. % % MATLAB555('Property','Value',...) creates a new MATLAB555 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Matlab555_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Matlab555_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 Matlab555 % Last Modified by GUIDE v2.5 02-Jun-2006 09:54:57 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Matlab555_OpeningFcn, ... 'gui_OutputFcn', @Matlab555_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 Matlab555 is made visible. function Matlab555_OpeningFcn(hObject, eventdata, handles, varargin) % Variables used by simulation/animation handles.output = hObject; handles.liquidlevel=0; %Level of liquid in tank handles.flow1=0; %Flow from supply (left to right) handles.flow2=0; %Flow into tank (left to right) handles.CloseWindow=0; %Set to 1 to close animation handles.DT=0.01; %Pause during animation. guidata(hObject, handles); %Update handles structure to reflect new data. while (handles.CloseWindow==0), if get(handles.PauseToggleButton,'Value')==0, DoSimulation(handles); %Do simulation step (Euler) end; pause(handles.DT); %Pause. DrawPicture(handles); %Draw picture %Load in Gui Data (in case CloseWindow has changed) handles=guidata(handles.MatLab555); end disp(' '); disp('Close 555 Animation'); disp(' '); disp(' '); close(handles.MatLab555); % --- Outputs from this function are returned to the command line. function varargout = Matlab555_OutputFcn(hObject, eventdata, handles) % varargout{1} = handles.output; %% Don't do anything. % --- Executes during object creation, after setting all properties. function W1EditText_CreateFcn(hObject, eventdata, handles) % 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 during object creation, after setting all properties. function W2EditText_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes during object creation, after setting all properties. function CEditText_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % Make sure W1 stays between 1 and 10. function W1EditText_Callback(hObject, eventdata, handles) W1=str2double(get(hObject,'String')); if W1>10, set(hObject,'String','10'); elseif W1<1, set(hObject,'String','1'); end; guidata(handles.MatLab555, handles); % Update handles structure % Make sure W2 stays between 1 and 10. function W2EditText_Callback(hObject, eventdata, handles) W2=str2double(get(hObject,'String')); if W2>10, set(hObject,'String','10'); elseif W2<1, set(hObject,'String','1'); end; guidata(handles.MatLab555, handles); % Update handles structure % Make sure C stays between 1 and 10. function CEditText_Callback(hObject, eventdata, handles) C=str2double(get(hObject,'String')); if C>10, set(hObject,'String','10'); elseif C<1, set(hObject,'String','1'); end; guidata(handles.MatLab555, handles); % Update handles structure % --- Executes on button press in AutomateCheckBox. function AutomateCheckBox_Callback(hObject, eventdata, handles) % Hint: get(hObject,'Value') returns toggle state of AutomateCheckBox % --- Executes on button press in ValveOpenCheckBox. function ValveOpenCheckBox_Callback(hObject, eventdata, handles) % Hint: get(hObject,'Value') returns toggle state of ValveOpenCheckBox % --- Executes on button press in ResetButton. function ResetButton_Callback(hObject, eventdata, handles) handles.liquidlevel=0; guidata(handles.MatLab555, handles); % Update handles structure % --- Executes on button press in PauseToggleButton. function PauseToggleButton_Callback(hObject, eventdata, handles) % --- Executes on button press in CloseButton. function CloseButton_Callback(hObject, eventdata, handles) handles.CloseWindow=1; guidata(handles.MatLab555, handles); % Update handles structure %Draw picture of tank, valve and fluid flow function DrawPicture(handles) axes(handles.Axes555); cla W1=str2double(get(handles.W1EditText,'String')); W2=str2double(get(handles.W2EditText,'String')); C=str2double(get(handles.CEditText,'String')); h=handles.liquidlevel; flow1=handles.flow1; flow2=handles.flow2; W1H=0.02*W1; % Height of R1 pipe W2H=0.02*W2; % Height of R2 pipe CW=0.01+0.015*C; % Width of C tank CL=0.7; CR=CL+CW; % Right side of C tank %Draw water and outer boundary of tank outerx=[0.05 0.05 CR CR]; outery=[0.95 0.2 0.2 0.95]; SH=0.7; TH=SH*h; waterx=[outerx 0.55 0.55]; watery=[0.2+SH 0.2 0.2 0.2+TH 0.2+TH 0.2+SH]; patch(waterx,watery,[0.5 0.5 1],'EdgeColor',[0.5 0.5 1]); line(outerx,outery,'LineWidth',2,'Color',[0 0 0]); %Erase extra water and draw inner boundary of tank innerx=[0.4 0.4 0.55 0.55 CL CL]; innery=[0.95 0.2+W1H 0.2+W1H 0.2+W2H 0.2+W2H 0.95]; patch(innerx,innery,[1 1 1],'EdgeColor',[1 1 1]); line(innerx,innery,'LineWidth',2,'Color',[0 0 0]); %Draw tick marks on tank. line([CR CR+0.02],[0.2+0.7/3 0.2+0.7/3],'LineWidth',2,'Color',[0 0 0]); line([CR CR+0.02],[0.2+2*0.7/3 0.2+2*0.7/3],'LineWidth',2,'Color',[0 0 0]); line([0.55 0.55], [0.2+W1H 0.2+max(W1H,W2H)+0.03],... 'LineWidth',2,'Color',[0 0 0]) %Check if valve is open - if so, modify drawing. if (get(handles.ValveOpenCheckBox,'Value')) waterx=[0.55-W1H/2 0.55-W1H/2 0.55+W2H/2 0.55+W2H/2]; watery=[0.21 0 0 0.21]; patch(waterx,watery,[0.5 0.5 1],'EdgeColor',[0.5 0.5 1]); x=[0.55 0.55]; y=[0.2+W1H 0.2-W2H]; line(x,y,'LineWidth',2,'Color',[0 0 0]); end %Draw arrows to indicate flow arrowScale=0.05; arrow(0.41,0.41+arrowScale*flow1,0.15); if flow2>0 arrow(0.56,0.56+arrowScale*flow2,0.10); else arrow(CL-0.01,CL-0.01+arrowScale*flow2,0.10); end function arrow(xt,xh,y) %Draw arrow alen=0.02; awdth=0.01; if (xt2/3 set(handles.ValveOpenCheckBox,'Value',1); elseif h<1/3 set(handles.ValveOpenCheckBox,'Value',0); end end handles.flow1=flow1; handles.flow2=flow2; handles.liquidlevel=h; guidata(handles.MatLab555, handles); % Update handles structure