Help Using readmatrix or readcell

14 ビュー (過去 30 日間)
Sean St Cyr
Sean St Cyr 2020 年 7 月 2 日
編集済み: the cyclist 2020 年 7 月 3 日
% Start writing your program here
% read excel file
%[GradesDat, GradesTxt] = xlsread('CU3141_Grades.xlsx'); THIS WAS THE ORIGINAL CODE
[GradesDat, GradesTxt]= readmatrix("CU3141_Grades.xlsx");
% store grade distribution (percentages) in a column vector "distribution"
distribution = [0.2; 0.4; 0.4];
% do inner product of grades matrix and distribution to get final grades
Final = GradesDat * distribution
% compute average grade using matlab's mean function
AveGrade = mean(Final)
% compute maximum grade using matlab's max function
MaxGrade = max(Final)
% determine maximum index using matlab's find function
MaxIndex = find(Final == MaxGrade)
% find student with maximum score
Students = GradesTxt(3:end); % extract only names for students
MaxStudent = Students(MaxIndex); % get the name of student with max score
MaxStudent = cell2mat(MaxStudent) % convert cell to character matrix (array)
% create the output message using matlab's sprintf function
Results = sprintf('The avaerage grade was %3.1f with a maximum score of %3.1f by %s.',AveGrade,MaxGrade,MaxStudent)
I am trying to not use xlsread and use readmatrix or readcell am I writing this wrong?
  1 件のコメント
dpb
dpb 2020 年 7 月 3 日
readcell will essentially return the same results as if you used the third, optional 'raw' output from xlsread -- everything will be returned as cell array instead of splitting the numeric and text data into two variables as does xlsread.
readmatrix only reads numeric data so it's not appropriate for your file.
Also NB cyclist's Answer that the syntax is wrong in there is only a single output from readmatrix or readcell, not an optional second or third as xlsread
Why are you changing? If anything, use readtable and rewrite the code to use the resulting table object given the apparent form of the file input.

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2020 年 7 月 2 日
編集済み: the cyclist 2020 年 7 月 3 日
According to the documentation, there is no two-output syntax for the readmatrix command. You'll need to get a deeper understanding of the differences between that command and xlsread.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by