Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Remember: You must write MATLAB code and then execute your code to produce outpu

ID: 3699859 • Letter: R

Question

Remember: You must write MATLAB code and then execute your code to produce output that solves this problem. You must show both your program and your program output in a screenshot(s) to receive full credit for this exercise You must also include a handwritten MATLAB program! Exercise 7 (4 pts): Following the same procedure that you used to solve the In-Class Programming Exercise #4, create AND IMPLEMENT IN MATLAB a pattern detector that can detect the pattern outlined in red, shown in figure 2 below. Then, answer the question at the end of this exercise, appearing after the two test matrices.

Explanation / Answer

Hello, I have pasted the code below and tested the code for the first input A given.

The output comes out to be 6 as mentioned in the question.

For the C matrix the output comes out to be 12.

You can execute the code and recheck the answers.

m = input('no. of rows: ');
n = input('no. of columns: ');
a=input('Enter the matrix in [* *;* *] format ')
a=reshape(a,m,n);
k=0;
for i=1:m-2
for j=1:n-2
if (a(i,j)==0) && (a(i,j+1)==1) && (a(i,j+2)==0) && (a(i+1,j)==1) && (a(i+1,j+1)==1) && (a(i+1,j+2)==0) && (a(i+2,j)==0) && (a(i+2,j+1)==1) && (a(i+2,j+2)==0)
k=k+1;
end
end
end
fprintf('Patterns found: %d ',k);