Working on an excel file

Hello. I am a beginner in matlab and i have a problem trying to work out the average of a row of an excel file in matlab. i am able to read the file in matlab and when calculating average i have to do it per unit and student. Also assist in a program that can output each student's result.
attached is the excel file.
[~, ~, data1] = xlsread('C:\Users\RONNIE\Documents\EXCEL.xlsx','Sheet1','A1:G81');
%finding average of each unit and writing it to excel
units=xlsread('EXCEL.xlsx',1,'B2:G81')
avg=mean(units{:'B'})
L=sum(units,1)/80;
xlswrite('EXCEL.xlsx',L,1,'B82');

Réponses (1)

KSSV
KSSV le 20 Juil 2022
Modifié(e) : KSSV le 20 Juil 2022
Don't use xlsread. Use readtable
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1071595/EXCEL.xlsx')
T = 80×7 table
NAMES LP MATLAB PDE STATS ANALYSIS FLUID _______________________ __ ______ ___ _____ ________ _____ {'Mandy Vance' } 80 8 38 45 77 44 {'Jermaine Mcmillan' } 11 29 15 93 22 54 {'Kristy Levy' } 30 89 38 74 19 20 {'Rudy Mcneil' } 38 67 87 73 23 31 {'Octavio Wheeler' } 81 28 85 5 51 54 {'Raquel Bass' } 49 70 17 93 19 61 {'Blake Colon' } 30 95 9 81 32 99 {'Rosetta Olsen' } 85 95 83 78 96 76 {'Esperanza Ross' } 74 2 24 77 89 31 {'Mable Strickland' } 10 74 79 69 89 32 {'Tameka Cameron' } 22 58 79 10 11 45 {'Marcelino Rasmussen'} 72 3 25 35 99 25 {'Pierre Galloway' } 83 25 19 20 38 57 {'Jake Chung' } 95 42 98 64 4 6 {'Jorge Oliver' } 52 82 35 35 66 14 {'Tracie Alvarez' } 75 65 12 89 27 87
You can access the subject, you want using:
T.MATLAB % use coloumn name
T.(3) % use column number

6 commentaires

Jay vee
Jay vee le 20 Juil 2022
whats the code for finding the average of each student and the average of each unit and writing them in the adjascent columns and rows?
KSSV
KSSV le 20 Juil 2022
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1071595/EXCEL.xlsx')
NAMES = T.(1) ;
AvgMarks = mean(table2array(T(:,2:end)),2) ;
Tavg = table(NAMES,AvgMarks)
Jay vee
Jay vee le 20 Juil 2022
Ooh thankss
what of assigning grades ...like A for marks above 70, B for 60-70 and so on and outputting each students marks ?
KSSV
KSSV le 20 Juil 2022
This you have to do.....
Jay vee
Jay vee le 20 Juil 2022
I can use the if statement to assign but i dont know how to display for each and every student.
T = readtable('C:\Users\RONNIE\Documents\EXCEL.xlsx')
NAMES = T.(1) ;
AvgMarks = mean(table2array(T(:,2:end)),2) ;
Tavg = table(NAMES,AvgMarks);
if (70<=AvgMarks)&&(AvgMarks<=100)
fprintf ('A')
elseif (60<=AvgMarks)&&(AvgMarks<=69)
fprintf ('B')
elseif (50<=AvgMarks)&&(AvgMarks<=59)
fprintf ('C')
elseif (40<=AvgMarks)&&(AvgMarks<=49)
fprintf ('D')
else
fprintf ('E')
end

Connectez-vous pour commenter.

Tags

Question posée :

le 20 Juil 2022

Commenté :

le 20 Juil 2022

Community Treasure Hunt

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

Start Hunting!

Translated by