matlab gui--数学建模长江水质的查询

第一此参加数学建模,接触到了matlab,后来又接触到了gui,我与它之间之间的爱恨情仇简直可以写成一本书了,但是这里我就不写书了,我还是直接贴代码吧。

我的感言:

下面是我的全部代码,之所以全部贴而不只贴一部分是因为在这之前我的学习经历,很多大佬写笔记都只写关键一部分,其他地方就什么都省略了,虽然自己都懂,但对于我这种初学者来说学习起来还是很困难的,主要是不能模仿自己试着编译。所以我贴出了所有的代码。

gui界面:

在这里插入图片描述

gui代码:

function varargout = Third_guides(varargin)
% THIRD_GUIDES MATLAB code for Third_guides.fig
%      THIRD_GUIDES, by itself, creates a new THIRD_GUIDES or raises the existing
%      singleton*.
%
%      H = THIRD_GUIDES returns the handle to a new THIRD_GUIDES or the handle to
%      the existing singleton*.
%
%      THIRD_GUIDES('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in THIRD_GUIDES.M with the given input arguments.
%
%      THIRD_GUIDES('Property','Value',...) creates a new THIRD_GUIDES or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Third_guides_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Third_guides_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 Third_guides

% Last Modified by GUIDE v2.5 30-Jul-2019 19:55:14

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Third_guides_OpeningFcn, ...
                   'gui_OutputFcn',  @Third_guides_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 Third_guides is made visible.
function Third_guides_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 Third_guides (see VARARGIN)

% Choose default command line output for Third_guides
handles.output = hObject;
handles                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Third_guides wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Third_guides_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 popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)

% hObject    handle to popupmenu1 (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 popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1

    

% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (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

% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)

guidata(hObject,handles);
% hObject    handle to popupmenu2 (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 popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2


% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (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 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



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (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 edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (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)
val=get(handles.popupmenu1,'value');
switch val
    case 1
        year='';
    case 2
        year=2003;
    case 3
        year=2004;
    case 4
        year=2005;
end
val=get(handles.popupmenu2,'value');
switch val
    case 1
        position=1;
    case 2
        position=2;
    case 3
        position=3;
    case 4
        position=4;
    case 5
        position=5;
    case 6
        position=6;
    case 7
        position=7;
    case 8
        position=8;
    case 9
        position=9;
    case 10
        position=10;
    case 11
        position=11;
    case 12
        position=12;
    case 13
        position=13;
    case 14
        position=14;
    case 15
        position=15;
    case 16
        position=16;
    case 17
        position=17;
    case 18
        position=18;
end
val=get(handles.popupmenu4,'value');
switch val
    case 1
        month=0;
    case 2
        month=1;
    case 3
        month=2;
    case 4
        month=3;
    case 5
        month=4;
    case 6
        month=5;
    case 7
        month=6;
    case 8
        month=7;
    case 9
        month=8;
    case 10
        month=9;
    case 11
        month=10;
    case 12
        month=11;
    case 13
        month=12;
end
if year==2003
    if month==6
        if position==9
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','溶解氧');
    elseif position==11
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','溶解氧、氨氮'); 
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==7
        if position==9
           set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','溶解氧');
        elseif position==10
            set(handles.edit1,'String','2类水');
            set(handles.edit2,'String','高锰酸盐指数');
        elseif position==11
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','高锰酸盐指数、溶解氧');
        elseif position==16
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','溶解氧');
        elseif position==18
            set(handles.edit1,'String','2类水');
            set(handles.edit2,'String','溶解氧');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==8
        if position==9
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
        elseif position==13
            set(handles.edit1,'String','2类水');
            set(handles.edit2,'String','溶解氧');
        elseif position==16
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==9
        if position==9
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
        elseif position==16
            set(handles.edit1,'String','劣V类水');
            set(handles.edit2,'String','氨氮');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==10
        if position==13
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','氨氮');
        elseif position==16
            set(handles.edit1,'String','劣V类水');
            set(handles.edit2,'String','氨氮');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==11
        if position==9
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','溶解氧、高锰酸盐指数');
        elseif position==13
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
        elseif position==16
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','氨氮');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==12
        if position==9
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮、高锰酸盐指数');
        elseif position==10
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','氨氮');
        elseif position==11
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','溶解氧、氨氮');
        elseif position==13
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
       elseif position==16
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','氨氮');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    else
            set(handles.edit1,'String','无数据');
            set(handles.edit2,'String','无数据');
    end
    set(handles.edit3,'String','全年排放270亿吨');
elseif year==2004
    if month==1
        if position==9
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
        elseif position==10
            set(handles.edit1,'String','5类水');
            set(handles.edit2,'String','氨氮');
        elseif position==11
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','溶解氧 ');
        elseif position==13
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
        elseif position==16
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','氨氮');
         else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==2
            if position==2
            set(handles.edit1,'String','2类水');
            set(handles.edit2,'String','氨氮');
        elseif position==9
            set(handles.edit1,'String','5类水');
            set(handles.edit2,'String','氨氮');
        elseif position==11
            set(handles.edit1,'String','5类水');
            set(handles.edit2,'String','氨氮 ');
        elseif position==13
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
        elseif position==16
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','溶解氧、氨氮');
        elseif position==17
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','高锰酸盐指数');
         else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
            end
    elseif month==3
        if position==9
            set(handles.edit1,'String','5类水');
            set(handles.edit2,'String','氨氮');
        elseif position==10
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','氨氮');
        elseif position==11
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','氨氮 ');
        elseif position==13
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
        elseif position==16
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','氨氮');
         else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==4
        if position==9
            set(handles.edit1,'String','5类水');
            set(handles.edit2,'String','溶解氧、高锰酸盐指数');
        elseif position==11
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','氨氮 ');
        elseif position==13
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
         else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==5
        if position==9
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','溶解氧');
        elseif position==11
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','溶解氧');
        elseif position==13
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮 ');
        elseif position==16
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','氨氮');
         else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==6
        if position==14
            set(handles.edit1,'String','2类水');
            set(handles.edit2,'String','高锰酸盐指数');
        elseif position==16
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','溶解氧');
         else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==7
        if position==9
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','氨氮');
        elseif position==14
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','高锰酸盐指数');
        elseif position==16
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','氨氮');
         else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==8
        if position==16
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
         else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
    end
    elseif month==9
        if position==2
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','高锰酸盐指数');
        elseif position==16
            set(handles.edit1,'String','5类水');
            set(handles.edit2,'String','溶解氧');
         else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==10
        if position==16
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮');
        elseif position==17
            set(handles.edit1,'String','2类水');
            set(handles.edit2,'String','高锰酸盐指数');
         else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==11
        if position==16
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','氨氮');
        elseif position==17
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','高锰酸盐指数');
         else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
        else
        if position==13
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','氨氮');
        elseif position==16
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','PH,氨氮');
        elseif position==17
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮'); 
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    end
        set(handles.edit3,'String','全年废水总排放量285吨');
elseif year==2005
    if month==1
        if position==9
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','氨氮');
        elseif position==16
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','氨氮');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==2
        if position==9
            set(handles.edit1,'String','5类水');
            set(handles.edit2,'String','氨氮');
        elseif position==13
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','氨氮');
        elseif position==14
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','高锰酸盐指数');
        elseif position==16
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','氨氮');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==3
        if position==16
            set(handles.edit1,'String','劣Ⅴ类水');
            set(handles.edit2,'String','氨氮');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==4
        if position==9
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','高锰酸盐指数、溶解氧');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==5
        if position==16
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','溶解氧');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==6
        if position==15
            set(handles.edit1,'String','3类水');
            set(handles.edit2,'String','溶解氧');
        elseif position==16
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮、溶解氧');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==7
        if position==16
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','氨氮、溶解氧');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==8
        if position==16
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','溶解氧');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    elseif month==9
        if position==16
            set(handles.edit1,'String','4类水');
            set(handles.edit2,'String','溶解氧');
        else
            set(handles.edit1,'String','无污染');
            set(handles.edit2,'String','无');
        end
    else
    set(handles.edit1,'String','无污染')
    set(handles.edit2,'String','无');
    end
set(handles.edit3,'String','全年总排放量303吨');
else
    set(handles.edit1,'String','无数据')
    set(handles.edit2,'String','无');
    set(handles.edit3,'String','无');
end
guidata(hObject,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)


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString=get(handles.edit1,'String');
textString=get(handles.edit2,'String');
textString=get(handles.edit3,'String');
set(handles.edit1,'String','');
set(handles.edit2,'String','');
set(handles.edit3,'String','');
guidata(hObject,handles);

% --- Executes on selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)

guidata(hObject,handles);
% hObject    handle to popupmenu4 (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 popupmenu4 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu4


% --- Executes during object creation, after setting all properties.
function popupmenu4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu4 (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
  • 7
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

村头卖假发的小郑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值