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: concatenate.m
    path of file: ./repos/CanlabCore/CanlabCore/External/spider/basic/@data_global
    
    the code of the file until where you have to start completion: 
function [d] = concatenate(tres,res,trn,tst)

%  function [d] = concatenate(trainRes,testRes,train,test)
%
%   Returns unified data (e.g with train and test results)
%   with trnRes in specified indexes train and tstRes in 
    
function [d] = concatenate(tres,res,trn,tst)

%  function [d] = concatenate(trainRes,testRes,train,test)
%
%   Returns unified data (e.g with train and test results)
%   with trnRes in specified indexes train and tstRes in 
%   indexes test.
      
  global X; global Y;
 
  [l1,n1,k1]=get_dim(res);
  [l2,n2,k2]=get_dim(tres);
  l=l1+l2; 
    
  globalx=1; globaly=1;
  if ~isempty(tres.myX) | ~isempty(res.myX)  globalx=0; end