function midtermGrades(grades)
    % Extract the student names and grades
    names = grades(2:end, 1);
    mathGrades = grades(2:end, 2);
    scienceGrades = grades(2:end, 3);
    englishGrades = grades(2:end, 4);
    historyGrades = grades(2:end, 5);
    csGrades = grades(2:end, 6);
    
    % Determine the grades 'S' or 'U' for each student
    finalGrades = cell(size(names));
    for i = 1:length(names)
        gradeCounts = [sum(mathGrades{i} == 'A' | mathGrades{i} == 'B' | mathGrades{i} == 'C'), ...
                       sum(scienceGrades{i} == 'A' | scienceGrades{i} == 'B' | scienceGrades{i} == 'C'), ...
                       sum(englishGrades{i} == 'A' | englishGrades{i} == 'B' | englishGrades{i} == 'C'), ...
                       sum(historyGrades{i} == 'A' | historyGrades{i} == 'B' | historyGrades{i} == 'C'), ...
                       sum(csGrades{i} == 'A' | csGrades{i} == 'B' | csGrades{i} == 'C')];
        if sum(gradeCounts) > (length(gradeCounts) - sum(gradeCounts))
            finalGrades{i} = 'S';
        else
            finalGrades{i} = 'U';
        end
    end
    
    % Display the grades table
    disp('Name   S/U');
    for i = 1:length(names)
        fprintf('%s   %s\n', names{i}, finalGrades{i});
    end
end

This MATLAB script defines a function called midtermGrades that takes a cell array called grades as input. This cell array represents the spreadsheet data with student names and their respective grades in different subjects. The function then processes this data to determine whether each student achieves a 'Satisfactory' (S) or 'Unsatisfactory' (U) grade based on the number of A's, B's, and C's they've earned. Finally, it presents the results in a neat table format with 'Name' and 'S/U' columns.

How it Works:

  1. Data Extraction: The function starts by extracting student names and their grades in each subject from the input grades cell array.
  2. Grade Calculation: For each student, the script counts the occurrences of 'A', 'B', and 'C' grades across all subjects. It then compares this count to determine if the majority of grades are passing ('S') or not ('U').
  3. Output Display: The final step involves neatly displaying the calculated 'S/U' grades alongside student names in a tabular format using the disp and fprintf functions.

This script provides a clear and efficient solution for automating the process of determining midterm 'S/U' grades from spreadsheet data, making it particularly useful for educators dealing with large classes or those looking to streamline their grading workflow using MATLAB.

MATLAB Script for Calculating Midterm 'Satisfactory' or 'Unsatisfactory' Grades from Spreadsheet Data

原文地址: https://www.cveoy.top/t/topic/kDQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录