Prev: reduce matrix size
Next: simultaneous equations system
From: Ralph on 11 Mar 2010 14:09 Hallo! I'm setting up some default options with a struct: defaults.color = 'r'; defaults.marker = 'o'; defaults.text = false; A user can now change some of the default option. e.g.: options.color = 'k'; Now I'd like to overwrite the default options with the options changed by the user: finaloptions = Overwrite(defaults, options) Giving: finaloptions.color = 'k'; finaloptions.marker = 'o'; finaloptions.text = false; Is there a function that does this for me or do I have to program it myself? Thanks, Ralph
From: jason on 11 Mar 2010 14:17 On Mar 11, 2:09 pm, "Ralph " <news2...(a)ecuapac.dyndns.org> wrote: > Hallo! > > I'm setting up some default options with a struct: > defaults.color = 'r'; > defaults.marker = 'o'; > defaults.text = false; > > A user can now change some of the default option. e.g.: > options.color = 'k'; > > Now I'd like to overwrite the default options with the options changed by the user: > finaloptions = Overwrite(defaults, options) > > Giving: > finaloptions.color = 'k'; > finaloptions.marker = 'o'; > finaloptions.text = false; > > Is there a function that does this for me or do I have to program it myself? > > Thanks, > Ralph why not initialize options.color to defaults.color then set finaloptions.color=options.color ?
From: Matt J on 11 Mar 2010 14:22 http://www.eecs.umich.edu/~fessler/irt/irt/utilities/vararg_pair.m
From: Ralph on 11 Mar 2010 14:27 jason <jason.mellone(a)gmail.com> wrote in message <1573bdf5- > why not initialize options.color to defaults.color > then set > finaloptions.color=options.color > ? Because the only thing the user should need to do is to setup those option they want to change. Yes, I could give them the defaults-structure but I don't want to. And yes, it's only cosmetics, I know. Ralph
From: Loren Shure on 11 Mar 2010 14:27
In article <hnbf4i$4ao$1(a)fred.mathworks.com>, news2008 @ecuapac.dyndns.org says... > Hallo! > > I'm setting up some default options with a struct: > defaults.color = 'r'; > defaults.marker = 'o'; > defaults.text = false; > > A user can now change some of the default option. e.g.: > options.color = 'k'; > > Now I'd like to overwrite the default options with the options changed by the user: > finaloptions = Overwrite(defaults, options) > > Giving: > finaloptions.color = 'k'; > finaloptions.marker = 'o'; > finaloptions.text = false; > > Is there a function that does this for me or do I have to program it myself? > > Thanks, > Ralph > You might find some good ideas in these 2 posts: http://blogs.mathworks.com/loren/2009/05/05/nice-way-to-set-function- defaults/ http://blogs.mathworks.com/loren/2009/05/12/optional-arguments-using- empty-as-placeholder/ -- Loren http://blogs.mathworks.com/loren http://matlabwiki.mathworks.com/MATLAB_FAQ |