diff dealStruct.m @ 920:386ef449df51 feature/d1_staggered

Merge with default.
author Martin Almquist <malmquist@stanford.edu>
date Wed, 28 Nov 2018 17:35:19 -0800
parents b7ec26da3d77
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dealStruct.m	Wed Nov 28 17:35:19 2018 -0800
@@ -0,0 +1,18 @@
+function varargout = dealStruct(s, fields)
+    default_arg('fields', []);
+
+    if isempty(fields)
+        out = dealFields(s, fieldnames(s));
+        varargout = out(1:nargout);
+    else
+        assert(nargout == length(fields), 'Number of output arguements must match the number of fieldnames provided');
+        varargout = dealFields(s, fields);
+    end
+end
+
+function out = dealFields(s, fields)
+    out = cell(1, length(fields));
+    for i = 1:length(fields)
+        out{i} = s.(fields{i});
+    end
+end