You are studying the number of defective parts produced each week by several mac
ID: 3806332 • Letter: Y
Question
You are studying the number of defective parts produced each week by several machines to help adjust maintenance protocols. Assume the rows of matrix Def represent different machines and all columns except the last represent weeks . The last column contains the long-term average of the number of defects per week produced by that machine. Write a short section of MATLAB code that will generate a new matrix Comp with the same number of rows but one fewer columns as described. The code will compare each value in the matrix, except those in the last column, to the value in the last column of the same row to compare the number of defective parts produced by each machine each week with that machine's long-term defect rate.
If the number of errors equals that machine's average, the corresponding element in the new matrix Comp will equal 0.
• If the number of errors is greater than that machine's average, the corresponding element in the new matrix Comp will equal 1.
• If the number of errors is less than that machine's average, the corresponding element in the new matrix Comp will equal -1.
Explanation / Answer
Answer: See the code below:
------------------------------------------
#This function processes Def matrix of size m x n. Rows of matrix Def
#represent different machines and all columns except the last represent weeks.
#The last column contains the long-term average of the number of defects per
#week produced by that machine. It is required generate a matrix Comp containing
#entries for corresponding weeks in Def telling whether defects in a week were
#greater than, less than or equal to the long term average of defects.
function Comp=processDefMatrix(Def,m,n)
Comp = zeros(m,n-1);
for i=1:m
for j=1:n-1
if (Def(i,j) == Def(i,n))
Comp(i,j) = 0;
elseif (Def(i,j) > Def(i,n))
Comp(i,j) = 1;
elseif (Def(i,j) < Def(i,n))
Comp(i,j) = -1;
end
end
end
end
-------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.