Hi This is my matlab problem Can you guys solve it Thanks Th

Hi. This is my matlab problem.
Can you guys solve it? Thanks.
The following table shows the scores in 3 quizzes where the first column is the score of quiz 1, the second column is the score of quiz 2 and the third column is the score of quiz 3, Assume the forth column is the ID# of the students in the class. 7 5 3 23 2 6 4 45 8 9 3 12 9 2 10 19 Assume a matrix, x has been defined as the table above. 1. Show using fprintf the ID# of the student who got the highest score in the second quiz using MATLAB commands (not by visual inspection of the data). 2. Show for each student their average score of the three quizzes. Code must use a built in function to calculate the average, and can not do manual calculation of each student.

Solution

1. A = [7 5 3 23; 2 6 4 45; 8 9 3 12; 9 2 10 19]

A =

7 5 3 23
2 6 4 45
8 9 3 12
9 2 10 19

[M,I] = max(A)
M =

9 9 10 45

I =

4 3 4 2

r = I(1,2)
r = 3
fileID = fopen(\'myfile.txt\',\'w\');
fprintf(fileID,\'The ID of the student is \',A(r, 4))
A(r,4)
ans = 12

M,I] = max(A) will get the largest numbers column wise where M represents the values and I represents the indices. We know that the second quiz is in the 2nd column and I will have only 1 row.

hence we can directly get the value of the index by using I(1,2). this value represents the index for the row where the student has the highest mark in quiz 2. The corresponding row in column 4 will give the student ID.

2. A = [7 5 3 23; 2 6 4 45; 8 9 3 12; 9 2 10 19]

A =

7 5 3 23
2 6 4 45
8 9 3 12
9 2 10 19

Removing the last column which contains the student ID
  
A(:,4) = []
A =

7 5 3
2 6 4
8 9 3
9 2 10

calculating the average row wise

B = mean(A,2)
B =

5.0000
4.0000
6.6667
7.0000

Hi. This is my matlab problem. Can you guys solve it? Thanks. The following table shows the scores in 3 quizzes where the first column is the score of quiz 1, t
Hi. This is my matlab problem. Can you guys solve it? Thanks. The following table shows the scores in 3 quizzes where the first column is the score of quiz 1, t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site