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: pm_diff.m
    path of file: ./repos/spm12/toolbox/FieldMap
    
    the code of the file until where you have to start completion: function D = pm_diff(V,dir)
% Calculate derivative in one direction of volume (matrix or memory mapped)
% FORMAT D = pm_diff(V,dir)
% V    - 3D array, or filestruct returned from spm_vol
% dir  - direction (1, 2 or 3 for x, y or z respectively)
%
% D    - 3D array of derivatives
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging


    
function D = pm_diff(V,dir)
% Calculate derivative in one direction of volume (matrix or memory mapped)
% FORMAT D = pm_diff(V,dir)
% V    - 3D array, or filestruct returned from spm_vol
% dir  - direction (1, 2 or 3 for x, y or z respectively)
%
% D    - 3D array of derivatives
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Chloe Hutton
% $Id: pm_diff.m 7120 2017-06-20 11:30:30Z spm $

if ischar(V)
   V   = spm_vol(V);
end