Homework 4, Problem 2, Trouble

I can't figure out what is wrong with my solution.
Write a function called checkerboard that takes as input two positive integer scalars, n and m, in that order. The function must create and return board, which is an n-by-m matrix. Every element of board is either 0 or 1. The first element, board(1,1) is 1. No direct neighbors in the matrix, vertically or horizontally, can be equal. That is, a 1 element cannot have 1 immediately preceding or following it in the same row or column.
This is my solution, but it has problem with arguments 1,1.
function board = checkerboard(A)
[n m] = size(A);
board = eye(n,m);
end

2 comentarios

Torsten
Torsten el 3 de Ag. de 2015
Google "checkerboard".
Best wishes
Torsten.
Brendan Hamm
Brendan Hamm el 3 de Ag. de 2015
Your solution will produce many neighbors which are equally 0 anytime n or m is greater than 2.

Iniciar sesión para comentar.

 Respuesta aceptada

Sean de Wolski
Sean de Wolski el 3 de Ag. de 2015

0 votos

checkerboard that takes as input two positive integer scalars
Yours is taking a matrix, A, it should take in n, m and not have to calculate them

1 comentario

Emily Lim
Emily Lim el 3 de Ag. de 2015
Thank you.
function board = checkerboard (n , m) board = zeros(n,m); board (1:2:n , 1:2:m)=1; board (2:2:n , 2:2:m)=1; end
This works.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 3 de Ag. de 2015

Comentada:

el 3 de Ag. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by