Search code examples
matlab

How to colour specific rectangles in a rectangular grid differently in Matlab


This Matlab script produces a grid of rectangles. I would like to color the bottom two rectangles on the right, differently. Cannot find how to do this hence my question

rH = 13500; % block height [um]
rL = 15000; % block height [um]

H = 2250; % rect height [um]
L = 5000; % rect length [um]


Grid = scale(nsidedpoly(4,'Side',1,'Center',[+1,+1]/2),[L,H]);
Grid = arrayfun(@(i)translate(Grid,H*[0,i]),0:ceil(rH/H)-1)';
Grid = arrayfun(@(i)translate(Grid,L*[i,0]),0:ceil(rL/L)-1,'uni',0);
Grid = vertcat(Grid{:}); 

plot(Grid,'FaceColor','w'); axis equal; hold on;

Solution

  • can't you add plot(Grid([7, 13]),'FaceColor','b');, to your code, which results in the following figure, I've included grid numbers as well which I added manually. colored grid