How do I create an x by y grid and how do I color each grid section?

18 views (last 30 days)
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
Walter Roberson
Walter Roberson on 27 Oct 2018
pcolor() is really surf() followed by view(2).
pcolor() interpolates face colors according to the surrounding four nodes.
If you want face colors directly you should be using imagesc()

Sign in to comment.

Accepted Answer

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

More Answers (0)


Find more on Strategy & Logic in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by