forked from widmann/sphspline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arg2str.m
70 lines (65 loc) · 2.22 KB
/
arg2str.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
% arg2str() - Convert function argument cell array or structure to
% EEGLAB compatible history string
%
% Usage:
% >> str = arg2str(arg);
%
% Inputs:
% arg - cell array arguments with parameter value pairs or
% structure arguments
%
% Outputs:
% str - history string
%
% Author: Andreas Widmann, University of Leipzig, 2006
%123456789012345678901234567890123456789012345678901234567890123456789012
% Copyright (C) 2006 Andreas Widmann, University of Leipzig, [email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
% $Id$
function str = arg2str(arg)
if isstruct(arg)
str = '';
fieldArray = fieldnames(arg);
arg = struct2cell(arg);
for iArg = 1:length(arg)
if ischar(arg{iArg})
str = [str '''' fieldArray{iArg} ''', ''' arg{iArg} ''''];
elseif isnumeric(arg{iArg}) || islogical(arg{iArg})
str = [str '''' fieldArray{iArg} ''', ' mat2str(arg{iArg})];
elseif iscell(arg{iArg})
str = [str '''' fieldArray{iArg} ''', ' arg2str(arg{iArg})];
end
if iArg < length(arg)
str = [str ', '];
end
end
elseif iscell(arg)
str = '{';
for iArg = 1:length(arg)
if ischar(arg{iArg})
str = [str '''' arg{iArg} ''''];
elseif isnumeric(arg{iArg}) || islogical(arg{iArg})
str = [str mat2str(arg{iArg})];
elseif iscell(arg{iArg})
str = [str arg2str(arg{iArg})];
end
if iArg < length(arg)
str = [str ' '];
else
str = [str '}'];
end
end
end