samer@3: function [Y,X0]=gathern(dim,n,X,varargin) samer@3: % gathern - make big array of n arrays in a sequence samer@3: % samer@3: % gathern :: N:natural, seq [D] -> [E], seq [D]. samer@3: % gathern :: samer@3: % D:natural ~'the dimension along which to collect arrays', samer@3: % N:natural ~'number of elements to collect', samer@3: % seq [D] ~'the seq to gather', samer@3: % options { samer@3: % draw :: boolean /0 ~'whether or not to call plotfn every iteration'; samer@3: % plotfn :: seq [D]->handle ~'plotting function'; samer@3: % save :: natural /0 ~'if >0, then save state every this many interations'; samer@3: % recover:: boolean / 0 ~'if 1, then attempt to restart from saved state'; samer@3: % id :: string /'@gather' ~'file to save state' samer@3: % } samer@3: % -> [E], seq [D]. samer@3: % samer@3: % E is such that E(I) = D(I) if I~=N. The second return samer@3: % is the final object in the sequence samer@3: samer@3: Y=[]; i=1; samer@3: if nargin<3 % simple version samer@3: if ~isempty(X), samer@3: Y=head(X); samer@3: i=1; while i0 samer@3: fprintf('Will save every %d iterations to %s.mat\n',savn,opts.id); samer@3: end samer@3: samer@3: if ~isempty(X) samer@3: Y=head(X); samer@3: i=1; while i0, delete([opts.id '.mat']); end samer@3: end samer@3: if nargout>1, if isempty(X), X0=X; else X0=next(X); end; end samer@3: end samer@3: samer@3: function nullplot(A,B), return