marksheet in matlab program

7 ビュー (過去 30 日間)
busy girl
busy girl 2020 年 12 月 8 日
編集済み: Image Analyst 2020 年 12 月 8 日
I have following data set in excel file
rollno name courses marks
12 abc maths 10
12 abc english 10
12 abc science 10
13 def maths 5
13 def english 5
12 def sciece 5
now i want to get total marks and percentage of each sutdent in next columns in excel file like below ... so how i do write matlab program
rollno name courses marks total marks perecentage
12 abc maths 10
12 abc english 10
12 abc science 10
30 50%
13 def maths 5
13 def english 5
12 def sciece 5
15 60%

回答 (1 件)

Image Analyst
Image Analyst 2020 年 12 月 8 日
編集済み: Image Analyst 2020 年 12 月 8 日
You forgot to attach the Excel workbook.
You'd do something like (untested)
[numbers, strings, raw] = xlsread(fileName);
% Then go down numbers looking for valid rows
rollno = numbers(:, 1);
marks = numbers(:, 4);
% Get rid of nan's
blankRows = isnan(rollno);
rollno = rollno(~blankRows);
marks = marks(~blankRows);
% Find the unique rolnos
uniqueNumbers = unique(rollno(~blankRows))
for rn = 1 : length(uniqueNumbers)
thisStudentID = uniqueNumbers(rn);
thisStudentIndexes = rollno == thisStudentID; % Logical vector
% Get average marks for this student
aveMarks(thisStudentID) = mean(marks(thisStudentIndexes));
% Get total marks for this student
totalMarks(thisStudentID) = sum(marks(thisStudentIndexes));
end
Of course you could use splitapply() or grpstats() if you want to do it in a single function call rather than a for loop.
Is it homework?
To Learn MATLAB:

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by