FOLLOW THE GIVEN CODE For this assignment, the function will take in a matrix of
ID: 2081209 • Letter: F
Question
FOLLOW THE GIVEN CODE
For this assignment, the function will take in a matrix of unknown size. Write a function that returns false(0) if any edge value is a zero. Otherwise, return a matrix or size equal to the original matrix that has a zero for any non-zero position or the largest number that is adjacent (in contact) to a zero. Example: Input matin = [1, 2, 3, 4; 5, 6,0, 8; 9, 2, 5, 2] Output matout = [0,0,0,0; 0,0, 8,0; 0,0,0,0] Solution function matout = nearZero(matin) %replace this line with your code endExplanation / Answer
function matout=nearzero(matin)
[m,n]=size(matin);
if(matin(1,1)==0 || matin(1,n)==0 || matin(m,1)==0 || matin(m,n)==0)
matout=zeros(m,n);
else
[m,n]=find(matin==0);
matout=zeros(m,n);
for i=1:length(m)
matout(m(i),n(i))=max(matin(m(i),(n(i)-1)),matin(m(i),(n(i)+11)));
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.