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: spm_meanm.m
    path of file: ./repos/bspm/thirdparty/spm12/toolbox/Longitudinal
    
    the code of the file until where you have to start completion: function M = spm_meanm(A)
% Compute barycentre of matrix exponentials
% FORMAT M = spm_meanm(A)
% A - A 3D array, where each slice is a matrix
% M - the resulting mean

    
function M = spm_meanm(A)
% Compute barycentre of matrix exponentials
% FORMAT M = spm_meanm(A)
% A - A 3D array, where each slice is a matrix
% M - the resulting mean
%
% Note that matrices should not be too dissimilar to each other or the
% procedure fails.
% See http://hal.archives-ouvertes.fr/hal-00699361/
%_______________________________________________________________________
% Copyright (C) 2012 Wellcome Trust Centre for Neuroimaging

% John Ashburner
% $Id: spm_meanm.m 4906 2012-09-06 17:30:56Z john $

N = size(A,3);
M = eye(size(A,1),size(A,2));

for iter = 1:1024,
    S = zeros(size(M));
    for i=1:N,
        L = real(logm(M\A(:,:,i)));
        S = S + L;
    end