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 EDITgui_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});endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});elsegui_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 grayset(ha,'handlevisibility','off','visible','off');%全局数据文件global dat;%打开文件夹 路径对话框,显示xls后缀的文件,等待选中[filename,pathname]=uigetfile('*.xls');file=[pathname,filename];%打开存有成绩的excel文件dat=xlsread('data.xls','','')%将成绩数据存到handle结构里handles.chengji=dathandles.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 untitledhandles.output = hObject;% Update handles structureguidata(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 structurevarargout{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_indexpopup_sel_index = get(handles.popupmenu1, 'Value');%将成绩数据从handle中提取出来到二维数组chengji中去ss=num2str(handles.chengji)chengji=str2num(ss)%提取成绩数组中1--20号的成绩到一维数组s中去for n=1:20s(n)=chengji(n,2)end%s行向量变成列向量as,便于显示as=dsort(s);%处理成绩数据进行排名for i=1:20for j=1:20if as(i)==s(j);bb(i)=j;endendendfor i=1:19kk=i+1;if as(i)==as(kk)k=bb(i)-1;for t=1:kif as(i)==s(t)bb(kk)=t;endendendend%获取最大值、最小值、平均值 、标准差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 ;endendset(handles.text6,'String','');switch popup_sel_indexcase 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:20s(n)=chengji(n,2)endaa=[0 0 0 0 0];%为直方图的绘制进行数据累加for i=1:20if s(i)<60aa(1)= aa(1)+1;elseif s(i)<70aa(2)= aa(2)+1;elseif s(i)<80aa(3)= aa(3)+1;elseif s(i)<90aa(4)= aa(4)+1;elseaa(5)= aa(5)+1;endendx=[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');endfunction 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');endfunction 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代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。










