📄 mingba.m
字号:
function varargout = mingba(varargin)% MINGBA Application M-file for mingba.fig% FIG = MINGBA launch mingba GUI.% MINGBA('callback_name', ...) invoke the named callback.% Last Modified by GUIDE v2.0 14-Mar-2003 06:14:40if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; endelseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try if (nargout) [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard else feval(varargin{:}); % FEVAL switchyard end catch disp(lasterr); endend%| ABOUT CALLBACKS:%| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism.%|%| Each callback subfunction declaration has the following form:%| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN)%|%| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback',%| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'.%|%| H is the callback object's handle (obtained using GCBO).%|%| EVENTDATA is empty, but reserved for future use.%|%| HANDLES is a structure containing handles of components in GUI using%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This%| structure is created at GUI startup using GUIHANDLES and stored in%| the figure's application data using GUIDATA. A copy of the structure%| is passed to each callback. You can store additional information in%| this structure at GUI startup, and you can change the structure%| during callbacks. Call guidata(h, handles) after changing your%| copy to replace the stored original so that subsequent callbacks see%| the updates. Type "help guihandles" and "help guidata" for more%| information.%|%| VARARGIN contains any extra arguments you have passed to the%| callback. Specify the extra arguments by editing the callback%| property in the inspector. By default, GUIDE sets the property to:%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))%| Add any extra arguments after the last argument, before the final%| closing parenthesis.% --------------------------------------------------------------------function varargout = edit1_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit2_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit3_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit4_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit5_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit6_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit7_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit8_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit9_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit10_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit11_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit14_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit15_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit16_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit17_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = pushbutton1_Callback(h, eventdata, handles, varargin)grid on;% --------------------------------------------------------------------function varargout = pushbutton2_Callback(h, eventdata, handles, varargin)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if ~isempty(get(handles.edit2,'String')) f2 = str2double(get(handles.edit2,'String')); %else warndlg('x2系数不能为零或空');end%zlim的获取clear f18 f19;f18 = str2double(get(handles.edit18,'String'));f19 = str2double(get(handles.edit19,'String'));if f18>=f19 errordlg('Z的最大值不能小于Z的最小值!','有错就改');end%设定slider初值slider_step(1) = 0.1/(f19-f18);slider_step(2) = 1/(f19-f18);av=f18+(f19-f18)/2;set(handles.slider1,'sliderstep',slider_step,... 'max',f19,'min',f18,'Value',av); %refresh the edit textz=get(handles.slider1,'Value');set(handles.edit20,'string',sprintf('%1.4g\',z));%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%f4 = str2double(get(handles.edit4,'String'));if ~isempty(get(handles.edit5,'String')) f5 = str2double(get(handles.edit5,'String'));else f5=0;endf6 = str2double(get(handles.edit6,'String')); if ~isempty(get(handles.edit7,'String')) f7 = str2double(get(handles.edit7,'String'));else f7=0;endf8 = str2double(get(handles.edit8,'String'));if ~isempty(get(handles.edit9,'String')) f9 = str2double(get(handles.edit9,'String'));else f9=0;endf10 = str2double(get(handles.edit10,'String'));if ~isempty(get(handles.edit11,'String')) f11 = str2double(get(handles.edit11,'String'));else f11=0;endf12 = str2double(get(handles.edit12,'String'));f13 = str2double(get(handles.edit13,'String'));f14 = str2double(get(handles.edit14,'String'));f15 = str2double(get(handles.edit15,'String'));f16 = str2double(get(handles.edit16,'String'));f17 = str2double(get(handles.edit17,'String'));n=1000;x1=linspace(f16,f17,n);one=ones(1,n);hold on;plot(x1,f4*x1+f5,'b');plot(x1,f6*x1+f7,'g');plot(x1,f8*x1+f9,'r');plot(x1,f10*x1+f11,'c');%ylimy1=max([f4*f17+f5,f4*f16+f5,f6*f17+f7,f6*f16+f7,f8*f17+f9,... f8*f16+f9,f10*f17+f11,f10*f16+f11,f15,f16]);y2=min([f4*f17+f5,f4*f16+f5,f6*f17+f7,f6*f16+f7,f8*f17+f9,... f8*f16+f9,f10*f17+f11,f10*f16+f11,f14,f17]);plot(f12*one,linspace(y1,y2,n),'k');plot(f13*one,linspace(y1,y2,n),'k');plot(x1,f14*one,'k');plot(x1,f15*one,'k');hold off;% --------------------------------------------------------------------function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)cla;% --------------------------------------------------------------------function varargout = togglebutton2_Callback(h, eventdata, handles, varargin)hold on;% --------------------------------------------------------------------function varargout = pushbutton5_Callback(h, eventdata, handles, varargin)hold on;% --------------------------------------------------------------------function varargout = pushbutton6_Callback(h, eventdata, handles, varargin)hold off;% --------------------------------------------------------------------function varargout = pushbutton7_Callback(h, eventdata, handles, varargin)grid off;% --------------------------------------------------------------------function varargout = edit18_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit19_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit20_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit21_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = slider1_Callback(h, eventdata, handles, varargin)%zlim的获取clear f18 f19;f18 = str2double(get(handles.edit18,'String'));f19 = str2double(get(handles.edit19,'String'));if f18>=f19 warndlg('Z的最大值不能小于Z的最小值!','这可是常识啊!');end%设定slider初值slider_step(1) = 0.1/(f19-f18);slider_step(2) = 1/(f19-f18);set(handles.slider1,'sliderstep',slider_step,... 'max',f19,'min',f18); %目标函数系数的获取z=get(handles.slider1,'Value');if ~isempty(get(handles.edit1,'String')) f1 = str2double(get(handles.edit1,'String'));else f1=0;endif ~isempty(get(handles.edit2,'String')) f2 = str2double(get(handles.edit2,'String')); %else errordlg('x2系数不能为零或空','下次可别忘了!');endif ~isempty(get(handles.edit3,'String')) f3 = str2double(get(handles.edit3,'String'));else f3=0;end%axis 上xlimf16 = str2double(get(handles.edit16,'String'));f17 = str2double(get(handles.edit17,'String'));%line of the aim functionn=1000;x1=linspace(f16,f17,n);one=x1.*zeros(1,n)+1;hold on;try plot(x1,(z-f1*x1-f3)/(f2),'r');catch errordlg('x2系数不能为零或空','下次可别忘了!');endhold off%refresh the edit textset(handles.edit20,'string',sprintf('%1.2g\',z));% --------------------------------------------------------------------function varargout = pushbutton8_Callback(h, eventdata, handles, varargin)zoom on;% --------------------------------------------------------------------function varargout = pushbutton9_Callback(h, eventdata, handles, varargin)zoom off;% --------------------------------------------------------------------function varargout = pushbutton10_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = pushbutton11_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit22_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit23_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit25_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit26_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit27_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = edit28_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = pushbutton12_Callback(h, eventdata, handles, varargin)%get the variables' valuef4 = str2double(get(handles.edit4,'String'));if ~isempty(get(handles.edit5,'String')) f5 = str2double(get(handles.edit5,'String'));else f5=0;endf6 = str2double(get(handles.edit6,'String')); if ~isempty(get(handles.edit7,'String')) f7 = str2double(get(handles.edit7,'String'));else f7=0;endf8 = str2double(get(handles.edit8,'String'));if ~isempty(get(handles.edit9,'String')) f9 = str2double(get(handles.edit9,'String'));else f9=0;endf10 = str2double(get(handles.edit10,'String'));if ~isempty(get(handles.edit11,'String')) f11 = str2double(get(handles.edit11,'String'));else f11=0;endf12 = str2double(get(handles.edit12,'String'));f13 = str2double(get(handles.edit13,'String'));f14 = str2double(get(handles.edit14,'String'));f15 = str2double(get(handles.edit15,'String'));f16 = str2double(get(handles.edit16,'String'));f17 = str2double(get(handles.edit17,'String'));n=1000;x1=linspace(f16,f17,n);one=ones(1,n);y1=max([f4*f17+f5,f4*f16+f5,f6*f17+f7,f6*f16+f7,f8*f17+f9,... f8*f16+f9,f10*f17+f11,f10*f16+f11,f15,f16]);y2=min([f4*f17+f5,f4*f16+f5,f6*f17+f7,f6*f16+f7,f8*f17+f9,... f8*f16+f9,f10*f17+f11,f10*f16+f11,f14,f17]);%xlim,ylimxmin=max(f12,f16);xmax=min(f13,f17); ymin=max(f14,y2);ymax=min(f15,y1);%clear certain variables clear f4 f5 f6 f7 f8 f9 f10 f11;%常数相if ~isempty(get(handles.edit5,'String')) f5 = str2double(get(handles.edit5,'String'));else f5=0;endif ~isempty(get(handles.edit7,'String')) f7 = str2double(get(handles.edit7,'String'));else f7=0;endif ~isempty(get(handles.edit9,'String')) f9 = str2double(get(handles.edit9,'String'));else f9=0;endif ~isempty(get(handles.edit11,'String')) f11 = str2double(get(handles.edit11,'String'));else f11=0;end%向量化n=10;x1=linspace(xmin,xmax,n);one=ones(1,n);hold on;%x1前系数t4=get(handles.edit4,'String');t6=get(handles.edit6,'String');t8=get(handles.edit8,'String');t10=get(handles.edit10,'String');if ~isempty(t4) f4 = str2double(get(handles.edit4,'String')); A=f4*x1+f5;else A=(ymax+1)*one;endif ~isempty(t6) f6 = str2double(get(handles.edit6,'String')); B=f6*x1+f7;else B=(ymax+1)*one;endif ~isempty(t8) f8 = str2double(get(handles.edit8,'String')); C=f8*x1+f9;else C=(ymin-1)*one;endif ~isempty(t10) f10 = str2double(get(handles.edit10,'String')); D=f10*x1+f11;else D=(ymin-1)*one;end%plothold on;x=linspace(xmin,xmax,n);loop=0;for ii=1:n; yy1(ii)=min([A(ii),B(ii),ymax]); yy2(ii)=max([C(ii),D(ii),ymin]); if yy1(ii)>yy2(ii) y=linspace(yy1(ii),yy2(ii),n); plot(x(ii)*one,y,'.c'); loop=1; endendif ~loop warndlg('公共区域不存在','让我轻轻地告诉你…………');endhold off % --------------------------------------------------------------------function varargout = pushbutton13_Callback(h, eventdata, handles, varargin)helpdlg(['如果您不太清楚某个按钮的功能,请将鼠标停留在该按钮上2秒即可得到相应提示 。 .'... '如果还有疑问,请email到我的邮箱: livefresh@163.com '... '或者tel: 8525124 马祥宁 '],'乐意为您效劳');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -