vendredi 25 octobre 2019

Matlab Homework

I am struggling with my Matlab homework: We

Write a script to do the following: 1.Generate a matrix called grades of size 8 x 25 that contains random numbers of type double in the range of 1 to 6. 2.Calculate the mean of matrix rows (-> mrow), the mean of matrix columns (-> mcol), and the overall mean (-> mall) of the matrix grades. 3.Copy the matrix grades to a new variable, in which you replace the elements in the 5th row and 20th to 23rd column with NaN. Compute the overall mean (-> mall_2) of this matrix again, i.e., the mean of the remaining values.

I am done with task 2-5, however, task 1 is not correct. I am not sure what I am doing wrong. I assume that it has something to do with the type of number (double), but I was unable to convert it.

% Generate matrix 'grades' with random numbers in the range 1 to 6

a = 1;
b = 6;
grades = (b-a).*rand(8,25) + a;

% calculate mean values 'mrow', 'mcol', 'mall'
mrow = mean(grades,2)
mcol = mean(grades,1)
mall = mean(grades(:))
% Replace elements with NaN
grades(5,20:23) = NaN
%Calculate mean of elements omitting NaN
mall_2 = mean(grades(:),'omitnan')

I would be thankful for any solution here!




Aucun commentaire:

Enregistrer un commentaire