function varargout = main(varargin)
% MAIN MATLAB code for main.fig
% MAIN, by itself, creates a new MAIN or raises the existing
% singleton*.
%
% H = MAIN returns the handle to a new MAIN or the handle to
% the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property','Value',...) creates a new MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to main_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 main
% Last Modified by GUIDE v2.5 08-Jan-2020 23:23:02
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_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 main is made visible.
function main_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 main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_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 button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton3 (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 radiobutton3
% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton4 (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 radiobutton4
% --------------------------------------------------------------------
function uibuttongroup2_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to uibuttongroup2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit12_Callback(hObject, eventdata, handles)
% hObject handle to edit12 (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 edit12 as text
% str2double(get(hObject,'String')) returns contents of edit12 as a double
% --- Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit12 (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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global l1 l2 M b bb u v a q h f flag sum total air;
sum=0;
if flag==0 %检查参数
errordlg('请检查参数','参数错误'); %参数错误处理
else %参数正确
cla(handles.axes1); %清除窗口
cla(handles.axes2);
cla(handles.axes3);
% cla(handles.axes5);
set(handles.edit10,'string',''); %清除显示
% set(handles.edit12,'string','');
% set(handles.edit11,'string','');
% set(handles.edit12,'string','');
t=0:0.01:l1/u; %求出烟草毒物密度w(x,t)
w0=M/l1; %初始毒物密度
q=a*u*w0/(1-a)*exp(-((b*l1+bb*l2)/v))*(exp(b*u*t/v)-a*exp(a*b*u*t/v));
%求出吸口端的流量q(l1+l2,t)
total=a*M*v/(1-a)/b/l1*exp(-bb*l2/v)*(1-exp((a-1)*b*l1/v));
%求出吸入毒物总量Q
air=u*w0*l1/u+a*w0*v/(1-a)/b*(exp((a-1)*b*l1*u/v/u)-1);
%求出进入空气毒物总量
% 动态图像绘制,同步显示
set(handles.axes1,'Visible','on');
set(handles.axes2,'visible','on');
set(handles.axes3,'visible','on');
set(h,'Visible','off');
set(f,'Visible','off');
axes(handles.axes2);
axis([0 l1/u 0 max(q)]);
axis on;
title('过滤嘴末端毒物流量随时间变化图','Color','y','fontsize',12);
xlabel('time');
ylabel('毒物流量');
hold on;
axis([0 l1/u 0 max(q)]);
wenzi=text(-10,-10,'');
axes(handles.axes1); %吸烟动态图
axis off;
title('吸烟过程动态示意图','Color','y','fontsize',16);
%title('xyh','Color','r')
rectangle('position',[0 0 10 4],'FaceColor',[0.71 0.77 0.69],'EdgeColor',[0.71 0.77 0.69]);
%背景
rectangle('position',[0 1.6 l1*10/(l1+l2) 0.8],'FaceColor','w');
%过滤嘴
rectangle('position',[l1*10/(l1+l2) 1.6 l2*10/(l1+l2) 0.8],'FaceColor','y');
%烟草
%烟草
for i=1:0.3:50
time=l1*i/50/u;
tt=time;
qt=q(round(u*length(q)*time/l1));
sum=sum+qt;
rectangle('position',[l1*i/5/(l1+l2) 1.6 l1/5/(l1+l2) 0.8],'FaceColor','r','EdgeColor','r');
rectangle('position',[l1*(i-1)/5/(l1+l2) 0 l1/5/(l1+l2) 4],'FaceColor',[0.71 0.77 0.69],'EdgeColor',[0.71 0.77 0.69]);
%背景条
hold on;
set(handles.edit10,'string',num2str(l1*i/50/u));
set(wenzi,'position',[tt qt],'string',num2str(qt));
axes(handles.axes2);
plot(tt,qt,'w-');
line([tt tt],[qt 0],'linewidth',3);
axes(handles.axes3);
axis([0 l1/u 0 M]);
xlabel('时间/t');
% ylabel('吸入毒物量')
title('吸入毒物量随时间变化图','Color','y','fontsize',12);
plot(tt,sum,'r.');
%wenzi1=text(-10,-15,'');
%set(w
评论11