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: homer2opto.m
    path of file: ./repos/fieldtrip/private
    
    the code of the file until where you have to start completion: function opto = homer2opto(SD)

% HOMER2OPTO converts the Homer SD structure to a FieldTrip optode structure
%
% See https://www.nitrc.org/plugins/mwiki/index.php/homer2:Homer_Input_Files#NIRS_data_file_format
%
% The Homer SD structure contains the source/detector geometry and has the following fields:
%
% nSrcs    - Number of lasers; scalar variable
% nDets    - Number of detectors; scalar variable
% SrcPos   - Array of probe coordinates of the lasers; dimensions <number of lasers> by 3
% DetPos   - Array of probe coordinates of the detectors; dimensions <number of detectors> by 3
% Lambda   - Wavelengths used for data acquisition; dimensions <number of wavelengths> by 1
% MeasList - List of source/detector/wavelength measurement channels. Itâ€™s an array with dimensions, <number of channels> by 4.The meaning of the 4 columns are as follows:
%   Column 1 index of the source from the SD.SrcPos list.
%   Column 2 index of the detector from the SD.DetPos list.
%   Column 3 is unused right now and contains all ones.
%   Column 4 index of the wavelength from SD.Lambda.
%
% The FieldTrip optode structure is defined in FT_DATATYPE_SENS
%
% See also OPTO2HOMER, BTI2GRAD, CTF2GRAD, FIF2GRAD, ITAB2GRAD, MNE2GRAD, NETMEG2GRAD, YOKOGAWA2GRAD, FT_DATATYPE_SENS

% Copyright (C) 2004-2020, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
%    FieldTrip is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    FieldTrip is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

    
function opto = homer2opto(SD)

% HOMER2OPTO converts the Homer SD structure to a FieldTrip optode structure
%
% See https://www.nitrc.org/plugins/mwiki/index.php/homer2:Homer_Input_Files#NIRS_data_file_format
%
% The Homer SD structure contains the source/detector geometry and has the following fields:
%
% nSrcs    - Number of lasers; scalar variable
% nDets    - Number of detectors; scalar variable
% SrcPos   - Array of probe coordinates of the lasers; dimensions <number of lasers> by 3
% DetPos   - Array of probe coordinates of the detectors; dimensions <number of detectors> by 3
% Lambda   - Wavelengths used for data acquisition; dimensions <number of wavelengths> by 1
% MeasList - List of source/detector/wavelength measurement channels. Itâ€™s an array with dimensions, <number of channels> by 4.The meaning of the 4 columns are as follows:
%   Column 1 index of the source from the SD.SrcPos list.
%   Column 2 index of the detector from the SD.DetPos list.
%   Column 3 is unused right now and contains all ones.
%   Column 4 index of the wavelength from SD.Lambda.
%
% The FieldTrip optode structure is defined in FT_DATATYPE_SENS
%
% See also OPTO2HOMER, BTI2GRAD, CTF2GRAD, FIF2GRAD, ITAB2GRAD, MNE2GRAD, NETMEG2GRAD, YOKOGAWA2GRAD, FT_DATATYPE_SENS

% Copyright (C) 2004-2020, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
%    FieldTrip is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    FieldTrip is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id$

M = size(SD.MeasList,1);  % number of channels
N = SD.nSrcs + SD.nDets;  % number of optodes
K = numel(SD.Lambda);     % number of wavelengths

% FIXME positions seem to be in degrees or so, not in mm or cm
if isfield(SD, 'SrcPos3D') && isfield(SD, 'DetPos3D')
  % use the 3D positions if available
  opto.optopos = cat(1, SD.SrcPos3D, SD.DetPos3D);
else
  % use the 2D positions
  opto.optopos = cat(1, SD.SrcPos, SD.DetPos);
end