How to plot a matrix in a checkerboard style

5 views (last 30 days)
I am trying to make my matrix Im look like the image below. I have tried playing around with the grid size, but to no avail...
Im = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 1 0 0 0 1 1 0 0 0 0 0 0 0;
0 1 0 0 0 0 1 0 0 0 0 1 0 0 0;
0 1 0 1 1 0 1 0 0 0 0 1 1 1 0;
0 0 0 1 1 0 1 0 0 0 0 1 0 0 0;
0 0 1 0 1 0 1 1 0 0 0 0 0 0 0;
0 0 0 1 1 0 1 1 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 1 0 0 0 0 0 1 0;
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0;
0 0 0 1 0 0 0 1 0 0 0 1 1 0 0;
0 0 1 1 0 0 1 1 0 0 0 1 0 0 0;
0 0 0 1 0 0 1 1 0 0 0 1 1 0 0;
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
];
figure
imagesc(Im)
grid on
set(gca,'xtick',[0:1:length(Im)])
set(gca,'ytick',[0:1:length(Im)])

Accepted Answer

DGM
DGM on 28 Nov 2021
Something like this should be a start:
Im = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 1 0 0 0 1 1 0 0 0 0 0 0 0;
0 1 0 0 0 0 1 0 0 0 0 1 0 0 0;
0 1 0 1 1 0 1 0 0 0 0 1 1 1 0;
0 0 0 1 1 0 1 0 0 0 0 1 0 0 0;
0 0 1 0 1 0 1 1 0 0 0 0 0 0 0;
0 0 0 1 1 0 1 1 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 1 0 0 0 0 0 1 0;
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0;
0 0 0 1 0 0 0 1 0 0 0 1 1 0 0;
0 0 1 1 0 0 1 1 0 0 0 1 0 0 0;
0 0 0 1 0 0 1 1 0 0 0 1 1 0 0;
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
];
hp = pcolor(padarray(Im,[1 1],'replicate','post'));
hp.EdgeColor = [1 0 0];
hp.LineWidth = 2;
colormap(gray(2))
set(gca,'ydir','reverse')
axis equal

More Answers (0)

Categories

Find more on Read, Write, and Modify Image 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!