Multiplying Matrices not working

% Start writing your program here
% read excel file
GradesTxt = readcell('CU3141_Grades.xlsx');
GradesDat = readmatrix('CU3141_Grades.xlsx');
% final grades
distribution = [0.2, 0.4,0.4];
Final = (GradesDat)*distribution;
AveGrade = mean(Final) %average grade
MaxGrade = max(Final) %maximum grade
MaxIndex = find(Final == MaxGrade)% maximum index
Students = GradesTxt(3:end,1); % 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 average grade was %.1f with a maximum score of %.1f by %s.',AveGrade,MaxGrade,MaxStudent)
I am trying to calculate a grades distribution and I understand that the matricies dont align, but when i try to change them to make them work it screws up the rest of my coding can anyone help?

Respuestas (1)

Walter Roberson
Walter Roberson el 3 de Jul. de 2020
Final = (GradesDat)*distribution.';

3 comentarios

Sean St Cyr
Sean St Cyr el 3 de Jul. de 2020
I am still getting the error of:
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
Error in solution (line 32)
Final = (GradesDat)*distribution.';
Walter Roberson
Walter Roberson el 3 de Jul. de 2020
What is size(GradesDat) ?
Your technique is only valid when the number of columns in GradeDat is the same as the number of elements in distribution.
By the way, your code needs to be more careful with the possibility that multiple students have the same maximum grade.
Sean St Cyr
Sean St Cyr el 3 de Jul. de 2020
It is a 13x4 however i need it to be a 13x3 correct? Because when I use the readmatrix it puts the NaN but would that effect the outcome?

Iniciar sesión para comentar.

Preguntada:

el 2 de Jul. de 2020

Comentada:

el 3 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by