28.2k views
3 votes
We are interested in creating a grid of n boxes by n boxes. Each box in the grid is 5 x 5 pixels and the surrounding black border is 1 pixel thick. The second last row and the second last column of the boxes are of cyan color (RGB = [0, 255, 255]), rest all are white. Write a program which displays such a grid based on the number of boxes given by the user. Assume that the user will always input a value greater than 4.

User Sgowd
by
4.3k points

1 Answer

4 votes

Answer:

clc

clear

size = input('Enter the number of boxes in a row : ');

for i=1:size

for j=1:size

if i==size-1 || j==2

rectangle('Position',[i*size,j*size,size,size],'FaceColor',[0,1,1],'EdgeColor','black',...

'LineWidth',3)

else

rectangle('Position',[i*size,j*size,size,size],'FaceColor',[1 1 1],'EdgeColor','black',...

'LineWidth',3)

end

end

end

Step-by-step explanation:

We are interested in creating a grid of n boxes by n boxes. Each box in the grid is-example-1
We are interested in creating a grid of n boxes by n boxes. Each box in the grid is-example-2
User Yokich
by
4.0k points