How to plot a matrix in a checkerboard style

조회 수: 4 (최근 30일)
Jimmy Neutron
Jimmy Neutron 2021년 11월 28일
답변: DGM 2021년 11월 28일
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)])

채택된 답변

DGM
DGM 2021년 11월 28일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by