%duplicateSubclusterRows duplicate sub-clustered rows of phase initialisation or ray coupling array

%   Copyright 2016-2018 The MathWorks, Inc.

%#codegen

function out = duplicateSubclusterRows(in,LOS,splitNLOS)

    offsetLOS = ~isempty(LOS);
    toSplit = unique(floor((splitNLOS-offsetLOS-1)/3)) + 1 + offsetLOS;
    
    NSC = numel(toSplit);
    M = size(in,2);
    Npol = size(in,3);
    split = nan(3*NSC,M,Npol);

    for s = 1:numel(toSplit)
        split((s-1)*3 + (1:3),:,:) = repmat(in(toSplit(s),:,:),[3 1 1]);
    end

    out = cat(1,in(LOS,:,:),split,in((max(toSplit)+1):end,:,:));
    
end
