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: writeCTFMRI.m
    path of file: ./repos/bspm/thirdparty/spm12/external/ctf
    
    the code of the file until where you have to start completion: function writeCTFMRI(fileName,MRItags,MRIdata);

% Version 1.2   25 April 2007   Module writeCPersist changed, and removed from this text
%                               file.
% Version 1.1   19 April 2007 : No changes from v1.0
% Version 1.0   27 Oct. 2006

%  Write a CTF MRI in v4 format.
%  For file format and a defineition fo CPersist objects, see document 
%  "CTF MEG FIle Formats", PN900-0088

%  Input: fileName : Name of MRI file  including path and extension.

%  Outputs: MRItags : CPersist tags describing the MRI in the format of the structure array
%                     produced by readMRI.  There must be no start and stop tags.
%                     Clnical use messages are added to _PATIENT_ID, _PATIENT_NAME,
%                     _STUDY_COMMENTS, _CTFMRI_COMMENTS.
%                      I.e  name='WS1_', type=0, data=[] and
%                           name
    
function MRItags=update_MRI_descriptors(MRItags,comment,creatorSoftware);

%  Makes sure that certain tags are in structure MRItags.

%  Inputs: MRItags : Structure array produced by readCTFMRI.
%          comment : Character string that is added to infods tags listed in addCommentTag.
%          creatorSoftware : Character string indicating that the MRI set was
%              created by writeCTFMRI.  Added to the tags listed in addCreatorTag.

%  Adds comment (clinical use message) and creator software name to 

%  MRI tags that will display the comment.
addCommentTag=strvcat('_PATIENT_ID','_PATIENT_NAME',...
  '_STUDY_COMMENTS','_CTFMRI_COMMENT');

%  MRI tags that will display the creator software.
addCreatorTag=strvcat('_CTFMRI_COMMENT');

%  Check that the comment and creator tags are in structure MRItags.  If not, issue an
%  error message and set MRItags to [].
addTag=strvcat(addCommentTag,addCreatorTag);
addIndex=zeros(1,size(addTag,1));
k=0;
for k=1:length(MRItags)
  tagIndex=strmatch(MRItags(k).name,addTag,'exact');
  addIndex(tagIndex)=k;
  if all(addIndex)~=0;break;end