diff --git a/lib/+artoa/+data/extractSoundsourcesFromStruct.m b/lib/+artoa/+data/extractSoundsourcesFromStruct.m index 55b89edf1d01ecddcb621fb304a7843cdd66b95f..63c77fa0c46e698089d8bc7deb8e607c044333b8 100644 --- a/lib/+artoa/+data/extractSoundsourcesFromStruct.m +++ b/lib/+artoa/+data/extractSoundsourcesFromStruct.m @@ -1,7 +1,18 @@ -function [extractedSoundsources] = extractSoundsourcesFromStruct(pSourcesToExtract, pSoundsources) +function [extractedSoundsources] = extractSoundsourcesFromStruct(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 = {}; @@ -13,5 +24,15 @@ for i = 1:length(pSourcesToExtract) 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