Effacer les filtres
Effacer les filtres

How to plot a matrix in a checkerboard style

3 vues (au cours des 30 derniers jours)
Jimmy Neutron
Jimmy Neutron le 28 Nov 2021
Réponse apportée : DGM le 28 Nov 2021
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)])

Réponse acceptée

DGM
DGM le 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

Plus de réponses (0)

Catégories

En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by