You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: generateBetaPatterns.m
    path of file: ./repos/bspm/thirdparty/rsatoolbox/Engines
    
    the code of the file until where you have to start completion: function OUT = generateBetaPatterns(clusterSpec, nVoxels, centroid)

% B = generateBetaPatterns(clusterSpec, nVoxels[, centroid])
%
% Generates a [nConditions nVoxels]-sized beta matrix of data where the
% responses are clustered according to clusterSpec (see below). Does not
% simulate scanner noise --- these simulated responses are "true".
%
%        B --- The beta matrix.
%                A [nConditions nVoxels]-sized matrix of simulated response.
%
%        clusterSpec --- Specification for the clustering of conditions.
%                clusterSpec is a cell array. Clustering of the conditions is
%                done in the following manner:
%                - Each cell represents a hierarchy.
%                - The first entry in a cell is the 'spread' of that level of
%                  the hierarchy.
%                - If the second entry is another cell, it and all following
%                  entries (which must also be cells) are sub-hierarchies.

    
function OUT = generateBetaPatterns(clusterSpec, nVoxels, centroid)

% B = generateBetaPatterns(clusterSpec, nVoxels[, centroid])
%
% Generates a [nConditions nVoxels]-sized beta matrix of data where the
% responses are clustered according to clusterSpec (see below). Does not
% simulate scanner noise --- these simulated responses are "true".
%
%        B --- The beta matrix.
%                A [nConditions nVoxels]-sized matrix of simulated response.
%
%        clusterSpec --- Specification for the clustering of conditions.
%                clusterSpec is a cell array. Clustering of the conditions is
%                done in the following manner:
%                - Each cell represents a hierarchy.
%                - The first entry in a cell is the 'spread' of that level of
%                  the hierarchy.
%                - If the second entry is another cell, it and all following
%                  entries (which must also be cells) are sub-hierarchies.
%                - If the second entry is a number (in which case there must
%                  only  be two entries), this number represents a number of
%                  'leaves', such that the cell is hierarchically an 'atom'.
%                So we have a well-defined recursive datatype for hierarchies.
%                For example,
%                        clusterSpec = {20, {6, {3, 5},{2, 3}}, {4, 7}}
%                represents the following hierarchy:
%                                            |
%                                ------------------------- 20
%                                |                       |
%                          ------------- 6               |
%                          |           |              ------- 4
%                        ----- 3      --- 2           |||||||
%                        |||||        |||             |||||||
%                         [5]         [3]               [7]
%
%        nVoxels --- The number of voxels in the simulated RoI.
%                An integer.
%
%        centroid --- The centre of the clusters.
%                This is mainly used for the recursion in this function, but
%                a vector of length nVoxels put here will centre the clusters
%                around this point in voxel space. Defaults to the origin.
%
% Cai Wingfield 6-2010
%__________________________________________________________________________
% Copyright (C) 2010 Medical Research Council

	% Probably on the first call, there is no centroid specified (an
	% implicit origin). Later, centroids will be picked based on the
	% results of previous iterations.
	if ~exist('centroid', 'var')
		centroid = zeros(1, nVoxels);
	end