Add second year
This commit is contained in:
@ -0,0 +1,9 @@
|
||||
function [grades] = clean_grades(grades)
|
||||
for i = 1:(size(grades,1)*size(grades,2))
|
||||
if grades(i) < 0
|
||||
grades(i) = 0;
|
||||
elseif grades(i) > 100
|
||||
grades(i) = 0;
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,4 @@
|
||||
function [grades] = create_grades(rows, columns, min, max, seed)
|
||||
rng(seed);
|
||||
grades = randi([min max], rows, columns);
|
||||
end
|
@ -0,0 +1,25 @@
|
||||
function [grades] = fill_estimates(grades)
|
||||
for i = 1:size(grades, 2)
|
||||
% making copy
|
||||
copy = grades(:, i);
|
||||
nonzero = 0; % count of nonzero elements to calculate avg
|
||||
sum = 0; % sum of nonzero elements
|
||||
|
||||
% looping through copy and counting number of nonzero elements
|
||||
for j = 1:size(copy,1)
|
||||
if copy(j) ~= 0
|
||||
nonzero = nonzero + 1;
|
||||
sum = sum + copy(j);
|
||||
end
|
||||
end
|
||||
|
||||
avg = round(sum / nonzero);
|
||||
|
||||
% looping through original and replacing any nonzero with average
|
||||
for j = 1:size(copy,1)
|
||||
if grades(j,i) == 0
|
||||
grades(j,i) = avg;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
4
second/semester2/CT248/Assignments/LabTest-1/test.m
Normal file
4
second/semester2/CT248/Assignments/LabTest-1/test.m
Normal file
@ -0,0 +1,4 @@
|
||||
clear;
|
||||
gr1 = create_grades(10,5,-10,110,100);
|
||||
gr2 = clean_grades(gr1);
|
||||
gr3 = fill_estimates(gr2);
|
Reference in New Issue
Block a user