在 Matlab 中输出一定比例的不同大小的矩阵

  • 本文关键字:Matlab 输出 matlab
  • 更新时间 :
  • 英文 :


我正在创建一个函数,该函数采用不同大小的矩阵并将总得分数转换为百分比。我觉得我错过了一个可以完成此操作的简单步骤。

function weight = calculatepercentage(exams, homework, quizzes);
exams = ([60,60]./60);
homework = ([30,30,30]./30);
quizzes = ([10,10,10,10]./10);
eScore = exams*.60;
hScore = homework*.25;
qScore = quizzes*.15;
disp(eScore + hScore + qScore)
end

这是一个可能正在完成这项工作的版本。您的函数正在覆盖您交给函数的变量。

final_score = calculatepercentage([60], [30 28], [5 5 5]);
function weight = calculatepercentage(exams, homework, quizzes)
% maximum points that can be obtained in each category
exam_maxpoints = 60;
homework_maxpoints = 30;
quizzes_maxpoints = 10;
% calc percentage per category
exams_percent = mean(exams./exam_maxpoints);
homework_percent = mean(homework./homework_maxpoints);
quizzes_percent = mean(quizzes./quizzes_maxpoints);
% calc percentage by weights for each category
eScore = exams_percent*.60;
hScore = homework_percent*.25;
qScore = quizzes_percent*.15;
% get final percentage
weight = eScore + hScore + qScore;
disp(weight)
end

相关内容

  • 没有找到相关文章

最新更新