Rev | Line | |
---|
[37] | 1 | function c = struct2arglist(s)
|
---|
| 2 | %STRUCT2ARGLIST Convert structure to cell array of fields/values.
|
---|
| 3 | % STRUCT2ARGLIST(S) returns a cell array {'field1',value1,'field2',value2,...}
|
---|
| 4 | % It is the opposite of MAKESTRUCT.
|
---|
| 5 | %
|
---|
| 6 | % Example:
|
---|
| 7 | % function f(varargin)
|
---|
| 8 | % opt.FontSize = 10;
|
---|
| 9 | % opt = setfields(opt,makestruct(varargin),'ignore');
|
---|
| 10 | % varargin = struct2arglist(opt);
|
---|
| 11 | % g(varargin{:});
|
---|
| 12 | %
|
---|
| 13 | % See also MAKESTRUCT.
|
---|
| 14 |
|
---|
| 15 | % Written by Tom Minka
|
---|
| 16 | % (c) Microsoft Corporation. All rights reserved.
|
---|
| 17 |
|
---|
| 18 | f = fieldnames(s);
|
---|
| 19 | c = cell(1,2*length(f));
|
---|
| 20 | for i = 1:length(f)
|
---|
| 21 | c{2*i-1} = f{i};
|
---|
| 22 | c{2*i} = s.(f{i});
|
---|
| 23 | end
|
---|
Note: See
TracBrowser
for help on using the repository browser.