% Loop over all sub-hypercubes
for i = 0:m^d-1
	% 'index' will be a vector with elements lying
	% in {0,1,...,m-1}
	index = zeros(1, d);
	for dim = 1:d
		index(dim) = mod(floor(i/(m^(dim-1))), m);
	end
	% Add the contribution at f(x_index) to the 
	% composite midpoint approximation
	% ...
end