1 简介
研究成绩管理系统可以极大地减少管理人员的工作量,系统地对学生的成绩和学生个人信息进行分析和做进一步处理.本文主要采用MATLAB的GUI界面,通过GUI制作一个简单的成绩查询系统界面.方便管理者管理学生的成绩和各类信息,使学校成绩管理和查询方法更科学和有效.
2 部分代码
function varargout = chengjichaxun(varargin)
% CHENGJICHAXUN M-file for chengjichaxun.fig
% CHENGJICHAXUN, by itself, creates a new CHENGJICHAXUN or raises the existing
% singleton*.
%
% H = CHENGJICHAXUN returns the handle to a new CHENGJICHAXUN or the handle to
% the existing singleton*.
%
% CHENGJICHAXUN('Property','Value',...) creates a new CHENGJICHAXUN using the
% given property value pairs. Unrecognized properties are passed via
% varargin to chengjichaxun_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% CHENGJICHAXUN('CALLBACK') and CHENGJICHAXUN('CALLBACK',hObject,...) call the
% local function named CALLBACK in CHENGJICHAXUN.M with the given input
% arguments.
%
% *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 chengjichaxun
% Last Modified by GUIDE v2.5 09-Jan-2014 16:38:01
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @chengjichaxun_OpeningFcn, ...
'gui_OutputFcn', @chengjichaxun_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin & isstr(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 chengjichaxun is made visible.
function chengjichaxun_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for chengjichaxun
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes chengjichaxun wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = chengjichaxun_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 during object creation, after setting all properties.
function edit_xm_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_xm (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_xm_Callback(hObject, eventdata, handles)
% hObject handle to edit_xm (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 edit_xm as text
% str2double(get(hObject,'String')) returns contents of edit_xm as a double
% --- Executes during object creation, after setting all properties.
function edit_xh_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_xh (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_xh_Callback(hObject, eventdata, handles)
% hObject handle to edit_xh (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 edit_xh as text
% str2double(get(hObject,'String')) returns contents of edit_xh as a double
% --- Executes during object creation, after setting all properties.
function edit_yw_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_yw (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_yw_Callback(hObject, eventdata, handles)
% hObject handle to edit_yw (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 edit_yw as text
% str2double(get(hObject,'String')) returns contents of edit_yw as a double
% --- Executes during object creation, after setting all properties.
function edit_sx_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_sx (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_sx_Callback(hObject, eventdata, handles)
% hObject handle to edit_sx (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 edit_sx as text
% str2double(get(hObject,'String')) returns contents of edit_sx as a double
% --- Executes during object creation, after setting all properties.
function edit_yy_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_yy (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_yy_Callback(hObject, eventdata, handles)
% hObject handle to edit_yy (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 edit_yy as text
% str2double(get(hObject,'String')) returns contents of edit_yy as a double
% --- Executes during object creation, after setting all properties.
function edit_wl_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_wl (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_wl_Callback(hObject, eventdata, handles)
% hObject handle to edit_wl (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 edit_wl as text
% str2double(get(hObject,'String')) returns contents of edit_wl as a double
% --- Executes during object creation, after setting all properties.
function edit_hx_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_hx (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_hx_Callback(hObject, eventdata, handles)
% hObject handle to edit_hx (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 edit_hx as text
% str2double(get(hObject,'String')) returns contents of edit_hx as a double
% --- Executes during object creation, after setting all properties.
function edit_sw_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_sw (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_sw_Callback(hObject, eventdata, handles)
% hObject handle to edit_sw (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 edit_sw as text
% str2double(get(hObject,'String')) returns contents of edit_sw as a double
% --- Executes during object creation, after setting all properties.
function edit_cxxm_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_cxxm (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_cxxm_Callback(hObject, eventdata, handles)
% hObject handle to edit_cxxm (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 edit_cxxm as text
% str2double(get(hObject,'String')) returns contents of edit_cxxm as a double
% --- Executes during object creation, after setting all properties.
function edit_cxxh_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_cxxh (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function wlpj_Callback(hObject, eventdata, handles)
% hObject handle to wlpj (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 wlpj as text
% str2double(get(hObject,'String')) returns contents of wlpj as a double
% --- Executes during object creation, after setting all properties.
function hxpj_CreateFcn(hObject, eventdata, handles)
% hObject handle to hxpj (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function hxpj_Callback(hObject, eventdata, handles)
% hObject handle to hxpj (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 hxpj as text
% str2double(get(hObject,'String')) returns contents of hxpj as a double
% --- Executes during object creation, after setting all properties.
function swpj_CreateFcn(hObject, eventdata, handles)
% hObject handle to swpj (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function swpj_Callback(hObject, eventdata, handles)
% hObject handle to swpj (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 swpj as text
% str2double(get(hObject,'String')) returns contents of swpj as a double
% --- Executes on button press in bccj.
function bccj_Callback(hObject, eventdata, handles)
% hObject handle to bccj (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
filename=get(handles.baocun,'string');
chengjibiao.xingming=get(handles.edit_xm,'string');
chengjibiao.xuehao=get(handles.edit_xh,'string');
chengjibiao.yuwen=get(handles.edit_yw,'string');
chengjibiao.shuxue=get(handles.edit_sx,'string');
chengjibiao.yingyu=get(handles.edit_yy,'string');
chengjibiao.wuli=get(handles.edit_wl,'string');
chengjibiao.huaxue=get(handles.edit_hx,'string');
chengjibiao.shengwu=get(handles.edit_sw,'string');
%%%计算总分
zongfen=str2num(chengjibiao.yuwen)+str2num(chengjibiao.shuxue)+str2num(chengjibiao.yingyu)+...
str2num(chengjibiao.wuli)+str2num(chengjibiao.huaxue)+str2num(chengjibiao.shengwu);
chengjibiao.zongfen=num2str(zongfen);
set(handles.edit_zf,'string',chengjibiao.zongfen)
save(filename,'chengjibiao') %保存文件
%%%保存成绩表为全局量,方便其他空间调用
handles.chengjibiao=chengjibiao;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function baocun_CreateFcn(hObject, eventdata, handles)
% hObject handle to baocun (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function baocun_Callback(hObject, eventdata, handles)
% hObject handle to baocun (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 baocun as text
% str2double(get(hObject,'String')) returns contents of baocun as a double
% --- Executes on button press in xhpx.
function xhpx_Callback(hObject, eventdata, handles)
% hObject handle to xhpx (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
xuehao=str2num(handles.chengjibiao.xuehao); %获得每个人的学号
%%%%%按学号排序
[fenshu mingci]=sort(xuehao); %将学号进行排名,获得各人的名次
chengjibiao.xingming=handles.chengjibiao.xingming(mingci,:);
chengjibiao.xuehao=handles.chengjibiao.xuehao(mingci,:);
chengjibiao.yuwen=handles.chengjibiao.yuwen(mingci,:);
chengjibiao.shuxue=handles.chengjibiao.shuxue(mingci,:);
chengjibiao.yingyu=handles.chengjibiao.yingyu(mingci,:);
chengjibiao.wuli=handles.chengjibiao.wuli(mingci,:);
chengjibiao.huaxue=handles.chengjibiao.huaxue(mingci,:);
chengjibiao.shengwu=handles.chengjibiao.shengwu(mingci,:);
chengjibiao.zongfen=handles.chengjibiao.zongfen(mingci,:);
set(handles.edit_xm,'string',chengjibiao.xingming);
set(handles.edit_xh,'string',chengjibiao.xuehao);
set(handles.edit_yw,'string',chengjibiao.yuwen);
set(handles.edit_sx,'string',chengjibiao.shuxue);
set(handles.edit_yy,'string',chengjibiao.yingyu);
set(handles.edit_wl,'string',chengjibiao.wuli);
set(handles.edit_hx,'string',chengjibiao.huaxue);
set(handles.edit_sw,'string',chengjibiao.shengwu);
set(handles.edit_zf,'string',chengjibiao.zongfen);
% --- Executes on button press in xmpx.
function xmpx_Callback(hObject, eventdata, handles)
% hObject handle to xmpx (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
yuwen=str2num(handles.chengjibiao.yuwen); %先获得语文的成绩,防止姓名里有空字符,通过语文成绩的个数来确定人数
[m,n]=size(yuwen); %得到人数(去除掉空的字符)
xingming=handles.chengjibiao.xingming; %获得每个人的姓名
%%%姓名不能转化为number,需要转换成单元数组之后,再进行排序
for iii=1:m
xm{iii}=xingming(iii,:);
end
%%%%%按姓名排序
[fenshu mingci]=sort(xm); %将姓名进行排名,获得各人的名次
chengjibiao.xingming=handles.chengjibiao.xingming(mingci,:);
chengjibiao.xuehao=handles.chengjibiao.xuehao(mingci,:);
chengjibiao.yuwen=handles.chengjibiao.yuwen(mingci,:);
chengjibiao.shuxue=handles.chengjibiao.shuxue(mingci,:);
chengjibiao.yingyu=handles.chengjibiao.yingyu(mingci,:);
chengjibiao.wuli=handles.chengjibiao.wuli(mingci,:);
chengjibiao.huaxue=handles.chengjibiao.huaxue(mingci,:);
chengjibiao.shengwu=handles.chengjibiao.shengwu(mingci,:);
chengjibiao.zongfen=handles.chengjibiao.zongfen(mingci,:);
set(handles.edit_xm,'string',chengjibiao.xingming);
set(handles.edit_xh,'string',chengjibiao.xuehao);
set(handles.edit_yw,'string',chengjibiao.yuwen);
set(handles.edit_sx,'string',chengjibiao.shuxue);
set(handles.edit_yy,'string',chengjibiao.yingyu);
set(handles.edit_wl,'string',chengjibiao.wuli);
set(handles.edit_hx,'string',chengjibiao.huaxue);
set(handles.edit_sw,'string',chengjibiao.shengwu);
set(handles.edit_zf,'string',chengjibiao.zongfen);
% --- Executes on button press in drcj.
function drcj_Callback(hObject, eventdata, handles)
% hObject handle to drcj (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[Filename Pathname]=uigetfile({'*.mat','Mat Files(*.mat)'},'请选择文件');
L=length(Filename);
if (L<5)
errordlg('没有选择文件!','文件打开错误') %%%%如果没有选择文件,提示错误信息
return
else
str=[Pathname Filename];
set(handles.xscj,'String',str)
end
Data=load(str); %读入成绩文件
chengjibiao=Data.chengjibiao; %Data是一个结构体,里面的chengjibiao为姓名,学号以及各科成绩等信息
%%%将读入的数据显示在成绩表中
set(handles.edit_xm,'string',chengjibiao.xingming);
set(handles.edit_xh,'string',chengjibiao.xuehao);
set(handles.edit_yw,'string',chengjibiao.yuwen);
set(handles.edit_sx,'string',chengjibiao.shuxue);
set(handles.edit_yy,'string',chengjibiao.yingyu);
set(handles.edit_wl,'string',chengjibiao.wuli);
set(handles.edit_hx,'string',chengjibiao.huaxue);
set(handles.edit_sw,'string',chengjibiao.shengwu);
set(handles.edit_zf,'string',chengjibiao.zongfen);
%%%保存成绩表为全局量,方便其他空间调用
handles.chengjibiao=chengjibiao;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function xscj_CreateFcn(hObject, eventdata, handles)
% hObject handle to xscj (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function xscj_Callback(hObject, eventdata, handles)
% hObject handle to xscj (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 xscj as text
% str2double(get(hObject,'String')) returns contents of xscj as a double
% --- Executes during object creation, after setting all properties.
function edit_zf_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_zf (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_zf_Callback(hObject, eventdata, handles)
% hObject handle to edit_zf (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 edit_zf as text
% str2double(get(hObject,'String')) returns contents of edit_zf as a double
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
3 仿真结果
4 参考文献
[1]杨文芳. 基于MATLAB设计学生成绩查询系统[J]. 考试周刊, 2016(75):1.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。