changeset 874:95993ad2bd70

Add function to deal the fields of a struct to variables
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 01 Nov 2018 14:10:02 +0100
parents 006defd0247b
children 5b06d4afa732
files dealStruct.m
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dealStruct.m	Thu Nov 01 14:10:02 2018 +0100
@@ -0,0 +1,9 @@
+function varargout = dealStruct(s, fields)
+    default_arg('fields', fieldnames(s));
+
+    assert(nargout == length(fields), 'Number of output arguements must match the number of fields');
+
+    for i = 1:length(fields)
+        varargout{i} = s.(fields{i});
+    end
+end