From 687feef43d7e360794b91b4e10bd97d922f5a4a7 Mon Sep 17 00:00:00 2001 From: Lewin Probst <info@emirror.de> Date: Sat, 16 Nov 2019 13:34:18 +0100 Subject: [PATCH] Added support to extract soundsources from struct as either struct or cell. --- .../+data/extractSoundsourcesFromStruct.m | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/+artoa/+data/extractSoundsourcesFromStruct.m b/lib/+artoa/+data/extractSoundsourcesFromStruct.m index 55b89ed..63c77fa 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 -- GitLab