Working on an excel file

조회 수: 1 (최근 30일)
Jay vee
Jay vee 2022년 7월 20일
댓글: Cris LaPierre 2022년 7월 20일
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');

답변 (1개)

KSSV
KSSV 2022년 7월 20일
편집: KSSV 2022년 7월 20일
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
Jay vee
Jay vee 2022년 7월 20일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by