MATLAB: How to create an x by y grid and how to color each grid section

game boardgrid patternstratego

I am currently creating the game stratego on matlab. I am not sure how to physically create the game board though. I am looking for something quite simple, just a grid pattern where I can manually color each square whatever color I want. Please help

Best Answer

You could use pcolor, here's a checkerboard example
A = repmat([repmat([1 0],1,10);repmat([0 1],1,10)],10,1)
pcolor(A)
You can build a color palette like this
cmap = [0 0 0;1 1 1;1 0 0;0 0 1;0 1 0];
colormap(cmap)
Now you can paint with these colors, by assigning values between, for example, 0 and 4 (you have 5 colors).
A(10,10)=4;
Makes the square at [10;10] green