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_extrapolate_def.m
    path of file: ./repos/ExploreASL/External/SPMmodified
    
    the code of the file until where you have to start completion: function Y = spm_extrapolate_def(Y,M)
% Fill in non-finite values in a deformation field
% FORMAT Y = spm_extrapolate_def(Y,M)
% Y - the deformation field
% M - voxel-to-world transform associated with the deformation
%     (for deriving voxel sizes)
%
% This function is typically used after generating an inverse deformation,

    
function Y = spm_extrapolate_def(Y,M)
% Fill in non-finite values in a deformation field
% FORMAT Y = spm_extrapolate_def(Y,M)
% Y - the deformation field
% M - voxel-to-world transform associated with the deformation
%     (for deriving voxel sizes)
%
% This function is typically used after generating an inverse deformation,
% as these may contain missing locations.
%__________________________________________________________________________
% Copyright (C) 2014 Wellcome Trust Centre for Neuroimaging

% John Ashburner
% $Id: spm_extrapolate_def.m 6137 2014-08-19 12:43:11Z john $

msk = isfinite(Y(:,:,:,1)); % Identify existing points
if ~all(msk(:)), % See if needed
    if nargin>=2,
        vx     = sqrt(sum(M(1:3,1:3).^2)); % Voxel sizes
    else
        vx     = [1 1 1];
    end