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

ONLY USE MATLAB TO ANSWER Function Name: brickLayer Inputs: 1. (double) The numb

ID: 671593 • Letter: O

Question

ONLY USE MATLAB TO ANSWER

Function Name: brickLayer


Inputs: 1. (double) The number of bricks to place vertically along the brick wall

2. (double) The number of bricks to place horizontally along brick wall

3. (char) Brick color

Outputs: 1. (char) An array of bricks

so the function header should look something like this: function out1 = brickLayer(in1 , in2, color)

THE ONLY OUTPUT SHOULD BE AN ARRAY OF BRICKS

Given a string indicating a brick color, create an array of bricks comprised of alternating colored and non-colored bricks. To ensure structural stability of the brick wall, the corners of the brick wall must be colored bricks. The format of the colored brick is given as the following:

'<space>[<input_color>]<space>'

For example, if given the brick color blue, your brick to then iteratively lay would be represented by a string such as:

' [blue] '. Non-colored bricks are the SAME SIZE as colored bricks but contain dashes (Ex: ' [----] ').

For ex:

array = brickLayer(5, 9, 'blue')

Notes: ? All bricks must be the same size, and each brick MUST be padded by a SPACE on either of its sides. Therefore, two juxtaposed bricks should have two spaces between them.

? We will only provide an odd number for the number of bricks to place vertically or horizontally along the brick wall.

Here are some sample fucntion calls and their corresponding outputs

Note how the class of the output would be class char so you can't use cell arrays

Hints: ? You may find a nested for loop useful for this problem.

? You may find it useful to nest conditional statements for this problem.

array => [blue] [ [blue] [blue][ [blue] [blue] [blue] [blue] [blue] blue] [] [blue] [ [blue] [blue][ [blue] [blue] bl bl] [ blue] [blue] -1 [blue] [ [blue] [blue][ [blue] [blue]

Explanation / Answer

%brickLayer.m

function out1 = brickLayer(in1 , in2, color)
out1 = cell(in1, in2);
for i = 1: in1
for j = 1: in2
if mod(i + j, 2) == 0
out1(i, j) = strcat('[', color, ']');
else
out1(i, j) = '[---]';
end
end
end
end