function [extractedSoundsources] = extract(pSourcesToExtract, pSoundsources, pAsStruct)
%EXTRACTSOUNDSOURCESFROMARRAY Summary of this function goes here
%   Detailed explanation goes here

%% Parameter check
if nargin == 2
    pAsStruct = false;
end

%% Return as structure if requested
if pAsStruct
    extractedSoundsources = createStruct();
    return;
end

%% Initialize return variable
extractedSoundsources = {};

%% Get all soundsources
for i = 1:length(pSourcesToExtract)
    try
        extractedSoundsources{end + 1} = pSoundsources.(pSourcesToExtract{i});
    catch
    end
end

    function [extractedSoundsources] = createStruct()
        extractedSoundsources = struct();
        for o = 1:length(pSourcesToExtract)
            if ~isfield(pSoundsources, pSourcesToExtract{o})
                continue;
            end
            extractedSoundsources.(pSourcesToExtract{o}) = pSoundsources.(pSourcesToExtract{o});
        end
    end

end