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: SOFAplotHRTF.m
    path of file: ./repos/SOFAtoolbox/SOFAtoolbox
    
    the code of the file until where you have to start completion: function [M,meta,h]=SOFAplotHRTF(Obj,type,varargin)
%SOFAplotHRTF - Plot HRTFs 
%   Usage: SOFAplotHRTF(Obj, type)
%          SOFAplotHRTF(Obj, type, R) 
%          SOFAplotHRTF(Obj, type, key,value)
%
%   SOFAplotHRTF(Obj, type) plots HRTFs of the first receiver (left ear) 
%   provided in Obj as the figure described by type: 
%     'EtcHorizontal'  Energy-Time Curve (ETC) in the horizontal plane (+/- THR)
%     'EtcMedian'      ETC in the median plane (+/- THR)
%     'MagHorizontal'  Magnitude spectra in the horizontal plane (+/- THR)
%     'MagMedian'      Magnitude spectra in the median plane (+/- THR)
%     'MagSagittal'    Magnitude spectra in a sagittal plane specified by OFFSET +/- THR
%     'MagSpectrum'    A single magnitude spectrum for given direction(s) DIR in COLOR
%     'ITDhorizontal'  Interaural time delays (ITDs) in the horizontal plane (Matlab only)
%
%   SOFAplotHRTF(Obj,type,key,value) defines the plotting in more detail:
%     'receiver' : Plot only specific receiver. Default: 1
%     'dir'      : Plot only specific positions (specify up to 0.1 accuracy).                   
%                  [azi]:         show all directions described by the azimuth angles azi.
%                  [azi, ele]:    show all directions described by the pairs of 
%                                 azimuth and elevation angles azi an ele, respectively.
%                  [azi, ele, r]: show only that specific positions described by the 
%                                 spherical coordinates azi, ele, and r.
%                  Default: [0,0].
%     'offset'   : Shifts the plane for which the HRTFs will be plotted. The amount of the 
%                  shift is described by value in degrees. 
%                  For plots in the horizontal plane, offset shifts the plane to be above the 
    
function 'npi2pi' removed (required toolbox in Matlab; in Octave not supported; outdated anyway) (08.02.2022)
% #Author: Michael Mihocic: keyvalue 'R'/'r' renamed to 'receiver' (10.05.2022)
% #Author: Michael Mihocic: 'do not convert' option enabled for SimpleFreeFieldHRTF convention; 
%                           global title only displayed if 'Obj.GLOBAL_Title' not empty (30.05.2022)
% #Author: Michael Mihocic: plotting simplefreefieldhrtf fixed (in Octave); titles fixed when plotting magspectrum (02.06.2022) 
% #Author: Michael Mihocic: plotting improved when data is available in TF format (more stable, no conversions by default);
%                           figure titles improved (04.07.2022) 
% #Author: Piotr Majdak: conversion to TF is a flag now. It's called convert2TF.
% #Author: Michael Mihocic: flag convert2TF renamed to conversion2ir and noconversion2ir. (01.09.2022)
% #Author: Robert Baumgartner: changed ITDhorizontal to plot absolute ITD values. (24.11.2022)
%
% Copyright (C) Acoustics Research Institute - Austrian Academy of Sciences;
% Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "License")
% You may not use this work except in compliance with the License.
% You may obtain a copy of the License at: https://joinup.ec.europa.eu/software/page/eupl
% Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing  permissions and limitations under the License.

% for backward compatibility (type as position-dependent input parameter)
if nargin == 3 && ischar(type) && isscalar(varargin{1})
%   varargin = flipud(varargin(:));
    R = varargin{1};
    flags.do_normalization=1;
    dir=[0,0];
    color='b';
    thr=2;
    offset=0;
    noisefloor=-50;             
%     convert=1; more comples differing below:

    if exist('OCTAVE_VERSION','builtin')
      % We're in Octave
       if ismember(type,{'MagHorizontal','MagMedian','MagSpectrum','MagSagittal'}) && ismember(lower(Obj.GLOBAL_SOFAConventions),{'freefielddirectivitytf','generaltf','simplefreefieldhrtf'})
          % In Octave 'contains' is not available, thus, the list has to be extend