source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/lightspeed/makestruct.m

Last change on this file was 37, checked in by (none), 14 years ago

Added original make3d

File size: 938 bytes
Line 
1function s = makestruct(varargin)
2%MAKESTRUCT   Cell-friendly alternative to STRUCT.
3% MAKESTRUCT('field1',value1,...) is similar to STRUCT but allows values to
4% be specified directly, i.e. cell arrays do not need to be wrapped.
5% If a field is specified more than once, the last value is taken.
6% You can also use MAKESTRUCT(C) where C is a cell array of fields/values.
7%
8% MAKESTRUCT is very useful for parsing argument lists.
9% Example:
10% function f(varargin)
11%   args = makestruct(varargin);
12%   default_args = struct('width',4,'height',4);
13%   args = setfields(default_args,args);
14%
15% See also STRUCT.
16
17% Written by Tom Minka
18% (c) Microsoft Corporation. All rights reserved.
19
20args = varargin;
21if length(args) == 1 && iscell(args{1})
22  args = args{1};
23end
24s = struct;
25for i = 1:2:length(args)
26  % this is much faster than 'setfield'
27  s.(args{i}) = args{i+1};
28  %s = setfield(s,args{i},args{i+1});
29end
Note: See TracBrowser for help on using the repository browser.