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: ComputeM0GivenR2star.m
    path of file: ./repos/sepia/utils
    
    the code of the file until where you have to start completion: %% function m0 = ComputeM0GivenR2star(r2s,te,img,method)
%
% Input
% ------------
    
function m0 = ComputeM0GivenR2star(r2s,te,img,method)
%
% Input
% --------------
%   r2s         : R2* map
%   te          : echo times
%   img         : multiecho images
%   method      : '1stecho','weighted','average'
%
% Output
% --------------
%   m0          : T1-weighted images
%
% Description: compute T1-wighted images given R2* and TE
%
% Kwok-shing Chan @ DCCN
% k.chan@donders.ru.nl
% Date created: 30 June 2017
% Date last modified:
%
%
function m0 = ComputeM0GivenR2star(r2s,te,img,method)
% get dimension of data
matrixSize = size(img);
ndim = ndims(img);

switch lower(method)
    case '1st echo'
        m0 = img(1:(numel(img)/matrixSize(end