How to write a Function that returns a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Write a function named checkerBoard that will receive a positive integer n as an input argument. The function will return an n-by-n matrix made up of alternating ones and zeros as shown in the example below. The first element of the matrix returned (first row, first column: ans(1,1) ) should be 1. I'm stuck on how to write the for loop?
4 comentarios
Sarah Sadeq
el 3 de Oct. de 2016
Editada: Walter Roberson
el 3 de Oct. de 2016
Walter Roberson
el 3 de Oct. de 2016
mod(n,n); doesn't do anything useful. It calculates a value and then throws the value away.
Respuestas (1)
Chi-Hsien Tang
el 30 de Sept. de 2016
Editada: Chi-Hsien Tang
el 30 de Sept. de 2016
Maybe try checkerboard(1,2,2)==0?
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!