how to create black and white checkerboards with different number of squares

1 view (last 30 days)
How can I create black and white checkerboard with different number of squares, for example, 2 squares, 4, 8, 16,32....
with the inbuilt checkerboard function, there is grey squares, which is undesirable

Accepted Answer

Adam Danz
Adam Danz on 18 Apr 2019
Edited: Adam Danz on 23 Apr 2019
The output of checkerboard() contains normalized values where 0 represents black, 1 represents white, and values between represent shades of gray. Just replace the values greater than 0 with 1.
I = checkerboard(20);
I(I>0) = 1;
imshow(I)
  3 Comments
Jimmy Liang
Jimmy Liang on 25 Apr 2019
And do you know can I grant values in the squares. for example, white squares represent a value(i.e. 10), black squares represent another value (i.e. 100). thank you so much

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!