Mercurial > repos > public > sbplib
comparison dealStruct.m @ 892:b7ec26da3d77
Handle default arguments better in dealStruct()
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 22 Nov 2018 07:26:45 +0100 |
parents | 95993ad2bd70 |
children |
comparison
equal
deleted
inserted
replaced
891:fd85412c7a99 | 892:b7ec26da3d77 |
---|---|
1 function varargout = dealStruct(s, fields) | 1 function varargout = dealStruct(s, fields) |
2 default_arg('fields', fieldnames(s)); | 2 default_arg('fields', []); |
3 | 3 |
4 assert(nargout == length(fields), 'Number of output arguements must match the number of fields'); | 4 if isempty(fields) |
5 | 5 out = dealFields(s, fieldnames(s)); |
6 for i = 1:length(fields) | 6 varargout = out(1:nargout); |
7 varargout{i} = s.(fields{i}); | 7 else |
8 assert(nargout == length(fields), 'Number of output arguements must match the number of fieldnames provided'); | |
9 varargout = dealFields(s, fields); | |
8 end | 10 end |
9 end | 11 end |
12 | |
13 function out = dealFields(s, fields) | |
14 out = cell(1, length(fields)); | |
15 for i = 1:length(fields) | |
16 out{i} = s.(fields{i}); | |
17 end | |
18 end |