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

~~~~~~~~~~~~~~~~~~~Please use MATLAB to answer the following questions, thank yo

ID: 3802400 • Letter: #

Question

~~~~~~~~~~~~~~~~~~~Please use MATLAB to answer the following questions, thank you!~~~~~~~~~~~~~~~~~~~

6. Write a function called myquadrants that takes one input integer argument n. The function returns an output matrix MQ which is a 2n-by-2n matrix MQ consists of four n-by-n submatrices. The elements of the submatrix in the top left corner are all 1s, the elements of the submatrix in the top right corner are all 2s, the elements of the submatrix in the bottom left corner are all 3s, and the elements of the submatrix in the bottom right corner are all 4s. Test your function with n 4.

Explanation / Answer

%matlab code

function MQ = myquadrants(n)
MQ = zeros(2*n,2*n);
row = 2*n;
column = 2*n;
  
for i=1:row
for j=1:column
if (i < n)
% 1st quadrant
if (j <= n)
MQ(i,j) = 1;
% 2nd quadrant
else
MQ(i,j) = 2;
end
else
% 3rd quadrant
if (j<= n)
MQ(i,j) = 3;
% 4th quadrant
else
MQ(i,j) = 4;
end
end
end
end
end


MQ = myquadrants(4)

%{
output:

MQ =
1 1 1 1 2 2 2 2
1 1 1 1 2 2 2 2
1 1 1 1 2 2 2 2
3 3 3 3 4 4 4 4
3 3 3 3 4 4 4 4
3 3 3 3 4 4 4 4
3 3 3 3 4 4 4 4
3 3 3 3 4 4 4 4

%}