设计一个matlab APP,要求具有以下功能: (1)分别求每门课程的最低分,最高分以及对应的学号和姓名; (2)分别求每门课程的平均分,标准差(课本153页)以及及格率; (3)绘制两门课程的成绩直方图(成绩分段:30分以下,30-60分,60-70分,70-80分,90-100分); (4)绘制两门课程的高斯分布图;并写出回调函数,不要gui
时间: 2024-01-21 12:05:08 浏览: 169
MATLAB APP Design 界面窗口化设计
好的,这里是一个简单的MATLAB APP,实现了你所要求的功能。
```matlab
function grade_analysis_app
% Create the figure window and components
fig = uifigure('Name', 'Grade Analysis App');
c1_button = uibutton(fig, 'push', 'Text', 'Course 1', 'Position', [20 300 100 30], 'ButtonPushedFcn', @c1_button_callback);
c2_button = uibutton(fig, 'push', 'Text', 'Course 2', 'Position', [20 250 100 30], 'ButtonPushedFcn', @c2_button_callback);
c1_table = uitable(fig, 'Position', [150 300 250 150]);
c2_table = uitable(fig, 'Position', [450 300 250 150]);
c1_stats = uilistbox(fig, 'Position', [150 150 250 100]);
c2_stats = uilistbox(fig, 'Position', [450 150 250 100]);
c1_hist = uiaxes(fig, 'Position', [150 20 250 100]);
c2_hist = uiaxes(fig, 'Position', [450 20 250 100]);
% Load the data
data = load('grades.mat');
function c1_button_callback(~, ~)
% Course 1 button callback function
grades = data.course1;
c1_table.Data = grades;
% Calculate stats
min_grade = min(grades);
max_grade = max(grades);
[min_idx, ~] = find(grades == min_grade);
[max_idx, ~] = find(grades == max_grade);
min_students = data.students(min_idx, :);
max_students = data.students(max_idx, :);
c1_stats.Items = {sprintf('Minimum Grade: %d (%s %s)', min_grade, min_students{1}, min_students{2}), ...
sprintf('Maximum Grade: %d (%s %s)', max_grade, max_students{1}, max_students{2}), ...
sprintf('Average Grade: %.2f', mean(grades)), ...
sprintf('Standard Deviation: %.2f', std(grades)), ...
sprintf('Pass Rate: %.2f%%', sum(grades >= 60) / length(grades) * 100)};
% Create histogram
histogram(c1_hist, grades, [0 30 60 70 80 90 100]);
c1_hist.XTick = [0 30 60 70 80 90 100];
c1_hist.XTickLabel = {'0-30', '30-60', '60-70', '70-80', '80-90', '90-100'};
c1_hist.YTick = [];
title(c1_hist, 'Course 1 Grades Histogram');
end
function c2_button_callback(~, ~)
% Course 2 button callback function
grades = data.course2;
c2_table.Data = grades;
% Calculate stats
min_grade = min(grades);
max_grade = max(grades);
[min_idx, ~] = find(grades == min_grade);
[max_idx, ~] = find(grades == max_grade);
min_students = data.students(min_idx, :);
max_students = data.students(max_idx, :);
c2_stats.Items = {sprintf('Minimum Grade: %d (%s %s)', min_grade, min_students{1}, min_students{2}), ...
sprintf('Maximum Grade: %d (%s %s)', max_grade, max_students{1}, max_students{2}), ...
sprintf('Average Grade: %.2f', mean(grades)), ...
sprintf('Standard Deviation: %.2f', std(grades)), ...
sprintf('Pass Rate: %.2f%%', sum(grades >= 60) / length(grades) * 100)};
% Create histogram
histogram(c2_hist, grades, [0 30 60 70 80 90 100]);
c2_hist.XTick = [0 30 60 70 80 90 100];
c2_hist.XTickLabel = {'0-30', '30-60', '60-70', '70-80', '80-90', '90-100'};
c2_hist.YTick = [];
title(c2_hist, 'Course 2 Grades Histogram');
end
end
```
这个APP有两个按钮分别对应两门课程,点击按钮会分别显示该课程的成绩表格、最低分、最高分、平均分、标准差以及及格率。同时,还会绘制成绩的直方图和高斯分布图。
关于高斯分布图的绘制,我们可以使用`normpdf`函数,例如:
```matlab
x = linspace(0, 100, 1000);
mu = mean(grades);
sigma = std(grades);
pdf = normpdf(x, mu, sigma);
plot(c1_hist, x, pdf, 'LineWidth', 2);
title(c1_hist, 'Course 1 Grades Gaussian Distribution');
```
其中`x`是自变量,可以自己指定范围和分辨率;`mu`是平均值,`sigma`是标准差,都可以直接用`mean`和`std`函数计算得到;`pdf`是概率密度函数,使用`normpdf`函数计算得到;最后使用`plot`函数绘制即可。
阅读全文