From: "David Epstein" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: coloured checkerboard
Date: Tue, 17 Apr 2012 22:27:07 +0000 (UTC)
Organization: Univ of Warwick
Lines: 10
Message-ID: <jmkqnr$pmo$>
References: <jmkf6l$apu$> <>
Reply-To: "David Epstein" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1334701627 26328 (17 Apr 2012 22:27:07 GMT)
NNTP-Posting-Date: Tue, 17 Apr 2012 22:27:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 319959
Xref: comp.soft-sys.matlab:764932

ImageAnalyst <> wrote in message <>...
> I'd probably make one colored square and one white (or black) square
> stitched together.  Then use repmat() to replicate that pair to
> complete the checkerboard.

Thanks. I did manage to figure this out soon after posting my question, though I'm still not sure I'm doing it as efficiently as possible. Despite what I originally said, I have decided it is simpler to index into the colormap.

I have d colours, not one and not two. My procedure is to stitch together d squares, each kxk and each with its own colour, in a column. This is now a d*k by k matrix. Using circshift(columnAlreadyConstructed,k) and stitching, I get a d*k x 2*k matrix. Applying circshift(matrixAlreadyConstructed, 2*k), I get a d*k x 4*k matrix. Continue like this until 2 to the appropriate power is greater than d. Cut the matrix down to a d*k by d*k matrix. Then use repmat to fill out the matrix completely. This actually gives a matrix that will be bigger than the original MxN asked for, but one can just take the first M rows and N columns.

That's the best I can do for now. I was missing circshift when I posted my question. I need to make these chequerboards as quickly as possible, because my code uses the operation quite often.