From: Andy A. <ad...@nc...> - 2005-05-12 01:39:15
|
I've made a change to the CVS to support this. Note, however, that s= struct() only works in newer versions of octave (works in 2.9.2 and not in 2.1.42 - I don't have others lying around to test) setfields now reads: function s = setfields(s,varargin) if nargin == 0 s= struct; % doesn't work on older versions of octave elseif rem(nargin,2) != 1, error('setfields: expected struct, key1, val1, key2, val2, ...\n') ; endif for i=1:2:nargin-1 if ! isstr(varargin{i}) , error('setfields: called with non-string key') ; else eval( ['s.',varargin{i},'=varargin{i+1};'] ) ; end end end >> Ben Barrowes wrote: OK. I encountered this because optimset.m has the line 45: opt = setfields (); which caused the original setfields.m: function s = setfields(s,varargin) if rem(nargin,2) != 1, error('setfields: called with odd number of arguments\n') ; endif to complain. nargin==0 should be a valid call to setfields, so maybe some easy fix would be: function s = setfields(s,varargin) if nargin>0 if rem(nargin,2) != 1, error('setfields: called with even number of arguments\n') ; endif else s=struct; end |