1 简介
设计一个基于GUI的学生成绩管理与分析系统
<1>、设计一个插入背景的登录界面
<2>、以某班某课成绩为研究对象,设计几个对话框,实现:
查询功能:
点击学生姓名,在列表视图显示相应的学号、成绩
统计功能:
读取数据库的学生成绩信息,进行统计从而绘制该课程学生成绩直方图(注释:学生成绩分几段,统计每段分数的人数,选择分数段中间数据,以此数据与人数为横、纵坐标,绘制直方图)以及饼图(对各分数段进行统计,便于直观的看出该课程成绩分布情况)
分析功能:
1)。该课的最低分、最高分以及相对应的学号
2)。该课程的平均分和均方差
3)。将该课程成绩按照从大到小排列、显示相对应学号
4)。按照学号显示学生成绩的原始分
<3>、设计退出系统的结束界面
2 部分代码
function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_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 untitled
% Last Modified by GUIDE v2.5 02-Jun-2012 12:45:16
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_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 untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
%全局数据文件
ha=axes('units','normalized','position',[0 0 1 1]);
uistack(ha,'down')
%II=imread('禾木01.bmp');%里面的参数可以是你自己的图片,把名字连同格式写进去就可以了
II=imread('dong1.jpg');
image(II)
colormap gray
set(ha,'handlevisibility','off','visible','off');
%全局数据文件
global dat;
%打开文件夹 路径对话框,显示xls后缀的文件,等待选中
[filename,pathname]=uigetfile('*.xls');
file=[pathname,filename];
%打开存有成绩的excel文件
dat=xlsread('data.xls','','')
%将成绩数据存到handle结构里
handles.chengji=dat
handles.output = hObject;
%保存已经改动的数据结构,这样才能在callbacks动作响应中使用
guidata(hObject, handles);
% 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 untitled (see VARARGIN)
% Choose default command line output for untitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_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 button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
%获取下拉框value值popup_sel_index
popup_sel_index = get(handles.popupmenu1, 'Value');
%将成绩数据从handle中提取出来到二维数组chengji中去
ss=num2str(handles.chengji)
chengji=str2num(ss)
%提取成绩数组中1--20号的成绩到一维数组s中去
for n=1:20
s(n)=chengji(n,2)
end
%s行向量变成列向量as,便于显示
as=dsort(s);
%处理成绩数据进行排名
for i=1:20
for j=1:20
if as(i)==s(j);
bb(i)=j;
end
end
end
for i=1:19
kk=i+1;
if as(i)==as(kk)
k=bb(i)-1;
for t=1:k
if as(i)==s(t)
bb(kk)=t;
end
end
end
end
%获取最大值、最小值、平均值 、标准差
mi =min(s);
ma=max(s);
mea=mean(s);
fc=std(s);
for i=1:20%获取最大值对应的学号
if mi==s(i)
mii=i ;
elseif ma==s(i)%获取最小值对应的学号
maa=i ;
end
end
set(handles.text6,'String','');
switch popup_sel_index
case 6%显示原始分
i=1:20;
set(handles.text4,'String',i);
set(handles.text5,'String',s);
set(handles.text6,'String','');
case 1%显示最大值及其学号
set(handles.text5,'String',ma);
set(handles.text4,'String',maa);
case 2%显示最小值及其学号
set(handles.text5,'String',mi);
set(handles.text4,'String',mii);
case 3%显示平均值
set(handles.text4,'String','');
set(handles.text5,'String',mea);
case 4%显示标准差
set(handles.text4,'String','');
set(handles.text5,'String',fc);
case 5%显示成绩排名
set(handles.text5,'String',as);
set(handles.text4,'String',bb);
cc=1:20;
set(handles.text6,'String',cc);
end
% 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)
axes(handles.axes1);
cla;
ss=num2str(handles.chengji)
chengji=str2num(ss)
for n=1:20
s(n)=chengji(n,2)
end
aa=[0 0 0 0 0];
%为直方图的绘制进行数据累加
for i=1:20
if s(i)<60
aa(1)= aa(1)+1;
elseif s(i)<70
aa(2)= aa(2)+1;
elseif s(i)<80
aa(3)= aa(3)+1;
elseif s(i)<90
aa(4)= aa(4)+1;
else
aa(5)= aa(5)+1;
end
end
x=[50 65 75 85 95];
%绘制直方图函数
bar(x,aa);
% 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)
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 Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in listbox2.
function listbox2_Callback(hObject, eventdata, handles)
% hObject handle to listbox2 (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 listbox2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox2
% --- Executes during object creation, after setting all properties.
function listbox2_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 selection change in listbox3.
function listbox3_Callback(hObject, eventdata, handles)
% hObject handle to listbox3 (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 listbox3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox3
% --- Executes during object creation, after setting all properties.
function listbox3_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 edit8_Callback(hObject, eventdata, handles)
% hObject handle to edit8 (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 edit8 as text
% str2double(get(hObject,'String')) returns contents of edit8 as a double
% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (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)
dlgTitle='填写学生相关信息';
lineNo=1;
prompt={'学号','成绩'};
def={'',''};
answer=inputdlg(prompt,dlgTitle,lineNo,def);
conna=database('Godman','','');
exdata=answer';
colnames={'学号','成绩'};
insert(conna,'stu',colnames,exdata)
close(conna)
%date=conna;
%c=xlsread('data.xls');
%xlwrite('data.xls',B),
%SUCCESS = XLSWRITE('d:\BWmatrix.xls',a,'A1:C3');
%我倒入数据用的是c=xlsread('tong.xls');
%导出数据用的是xlswrite(‘文件位子和名称’,矩阵名,'excel的页码','第几行第几列');
%xlswrite('C:\Users\aa\Desktop\计算机仿真课程设计\data.xls’,def,'0,'c+11');
%xlswrite('C:\Users\aa\Desktop\计算机仿真课程设计\data.xls’,def,'0,'c+12');
conna=database('Godman','','');
curs=exec(conna,'select 姓名 from stu');
curs=fetch(curs);
data=curs.Data;
close(curs)
close(conna)
%set(handles.text4,'string',data[0]);
%set(handles.text5,'string',data[1]);
% 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)
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h=gcf;untitledend; close(h);
3 仿真结果
4 参考文献
[1]任治斌, and 单蓉. "基于Matlab的学生成绩综合分析." 宁夏师范学院学报 31.6(2010):4.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。