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: writeGIF.m
    path of file: ./repos/gptoolbox/imageprocessing
    
    the code of the file until where you have to start completion: function writeGIF(filename,X,M,D)
  % WRITEGIF imwrite is bad at writing animated figs. This allows per frame
  % delays
  % 
  % writeGIF(filename,X,M,D)
  %
  % Inputs:
  %   filename  path to .gif file
  %   X  h by w by 3 by #frames list of indexed images

    
function writeGIF(filename,X,M,D)
  % WRITEGIF imwrite is bad at writing animated figs. This allows per frame
  % delays
  % 
  % writeGIF(filename,X,M,D)
  %
  % Inputs:
  %   filename  path to .gif file
  %   X  h by w by 3 by #frames list of indexed images
  %   M  h by w by (1|#frames) list of maps
  %   D  (1|#frames)  list of delays
  % 
  % See also, hack to get imread to read animated gifs correctly:
  % http://www.alecjacobson.com/weblog/?p=4726
  %
  % Example:
  %  % Load in a one-way animation
  %  [X,M] = imread('bunny.gif');
  %  % Trim to animations extent
  %  Y = imtrim(X,'Map',M,'Threshold',0);
  %  % Write a "boomerang": looping back-and-forth image, pausing at end