I have achieved what I wanted with the following code.
function [ XV, YV ] = gen_clusters( rs,dc,X )
%GEN_CLUSTERS Generates the vertices of every cluster in the network.
%Input: rs - Side length of network
% dc - Side length of cluster
% X - Matrix X from meshgrid
%Output: XV - x-coordinates of clusters
% YV - y-coordinates of clusters
%XV and YV are nx5 matrices where n is the number of clusters. 5 columns
%are needed because the 5th column closes the cluster.
% Calculate no. of clusters
n = rs/dc;
XV = zeros(n,4);
% Calculate XV
for i = 1:n
XV(i,:) = [repmat(X(1,i),1,2) repmat(X(1,i+1),1,2)];
% Calculate YV based on XV
YV = repmat(XV,n,1);
YV = circshift(YV,[0 -1]);
YV(:,5) = YV(:,1);
% Duplicate rows of XV n times
XV = reshape(repmat(XV(:)',n,1),,4);
XV(:,5) = XV(:,1);