Last active
November 29, 2022 06:31
-
-
Save HsuChiChen/289a18b088ab17fd5caaee31b56ba566 to your computer and use it in GitHub Desktop.
讀取excel文件中指定全班分數表格,繪製各個成績區間累積人數的直方圖(Histogram)與整體數據的高斯分布,兩者做疊圖。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% read file | |
clc, clear, close all | |
data = readmatrix('vlsi.xlsx'); % file name | |
score = data(1:86, 14); % extract score array | |
%% histogram plot | |
hold on; | |
grid on; | |
xlim([0,100]); | |
title('score distribution of VLSI circuit final exam','FontSize',15); | |
xlabel('score', 'FontSize',15); | |
ylabel('number of people','FontSize',15); | |
score_object = histogram(score,'FaceColor','#0072BD'); | |
% score_object.BinWidth = 10; % interval between bars | |
counts = score_object.Values; | |
counts_height = score_object.BinEdges; | |
for n = 1:length(counts) | |
text(counts_height(n) + 3.5,counts(n) + 1 ,num2str(counts(n)),'FontSize',20,'Color','#0072BD'); | |
end | |
%% Gaussian distribution | |
std_s = std(score); | |
mean_s = mean(score); | |
x = 0:0.1:100; | |
r = normpdf(x,mean_s,std_s); | |
yyaxis right | |
plot(x,r,'LineWidth',2,'Color','#D95319') | |
set(gca,'YTickLabel',[]); | |
[max_value,max_index] = max(r); | |
plot(x(max_index),r(max_index),'.','MarkerSize',20,'Color','#7E2F8E'); | |
hold off; | |
% %% ranking | |
% ranking = sort(score,'descend'); | |
% prompt = "enter your score :"; | |
% | |
% while true | |
% your_score = input(prompt); | |
% number = find(ranking == your_score); | |
% if isempty(number) | |
% fprintf('\nThe score you entered is not in list\n'); | |
% else | |
% fprintf('\n ranking : %d / %d (percentage : %.1f)\n',number(1), length(ranking),(number(1)/length(ranking))*100); | |
% end | |
% end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment