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: VBA_spm_perm_mtx.m
    path of file: ./repos/VBA-toolbox/thrid-party/spm
    
    the code of the file until where you have to start completion: function [K] = VBA_spm_perm_mtx(n)
% Returns a matrix of indices permuted over n
% FORMAT [K] = spm_perm_mtx(n)

    
function [K] = VBA_spm_perm_mtx(n)
% Returns a matrix of indices permuted over n
% FORMAT [K] = spm_perm_mtx(n)
%    n   - (scalar) number of indices
%    K   - (2^n x n) permutation matrix
%    n   - (vector) indices
%    K   - (length(n)! x n) permutation matrix
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
 
% Karl Friston
% $Id: spm_perm_mtx.m 5657 2013-09-26 16:53:40Z karl $
 
% get permutations
%==========================================================================

% permute zeros and ones
%--------------------------------------------------------------------------
if isscalar(n)
    
    N  = 2^n;
    K  = sparse(N,n);
    x  = sparse(1,1,1,2,1);
    for i = 1:n
        y      = ones(N/length(x),1);
        K(:,i) = kron(x,y);
        x      = [x;x];
    end