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: metaImageWrite.m
    path of file: ./repos/matImage/matImage/imStacks
    
    the code of the file until where you have to start completion: function metaImageWrite(img, fileName, varargin)
% Save image data using MetaImage file format (MHD).
%   
%   metaImageWrite(IMG, FILENAME);
%   IMG is a matlab array, and FILENAME is the generic name (without
%   extension) of the metaimage file.
%   The functions tries to
    
function string = convertToString(data)
% Utility function that converts logical or numeric data to char array.

N = length(data(:));

if ischar(data)
    string = data;
    
elseif islogical(data)
    strings = {'false', 'true'};
    pattern = ['%s' repmat(' %s', 1, N-1)];
    string = sprintf(pattern, strings{data(:)+1});
    
elseif isinteger(data)
    pattern = ['%d' repmat(' %d', 1, N-1)];
    string = sprintf(pattern, data(:));
    
elseif isfloat(data)
    pattern = ['%g' repmat(' %g', 1, N-1)];
    string = sprintf(pattern, data(:));
    
else
    error('Unknwon type of data');
end