Mercurial > hg > octave-nkf
changeset 16978:00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
* scripts/special-matrix/gallery.m: Add 'uniformdata' matrix to function.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 13 Jul 2013 19:28:24 -0700 |
parents | 0d5d3e53255f |
children | 9aa293e00475 |
files | scripts/special-matrix/gallery.m |
diffstat | 1 files changed, 39 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/special-matrix/gallery.m +++ b/scripts/special-matrix/gallery.m @@ -22,7 +22,6 @@ ## @deftypefnx {Function File} {} gallery (@var{name}, @var{args}) ## Create interesting matrices for testing. ## -## ## @end deftypefn ## ## @deftypefn {Function File} {@var{c} =} gallery ("cauchy", @var{x}) @@ -434,8 +433,7 @@ case "toeppen" , [varargout{1:n_out}] = toeppen (varargin{:}); case "tridiag" , [varargout{1:n_out}] = tridiag (varargin{:}); case "triw" , [varargout{1:n_out}] = triw (varargin{:}); - case "uniformdata" - error ("gallery: matrix %s not implemented.", name); + case "uniformdata" , [varargout{1:n_out}] = uniformdata (varargin{:}); case "wathen" , [varargout{1:n_out}] = wathen (varargin{:}); case "wilk" , [varargout{1:n_out}] = wilk (varargin{:}); otherwise @@ -2426,6 +2424,44 @@ t = tril (eye (m, n) + alpha * triu (ones (m, n), 1), k); endfunction +function A = uniformdata (varargin) + + if (nargin < 2) + error ("gallery: At least 2 argument required for uniformdata matrix."); + endif + if (isnumeric (varargin{end})) + jidx = varargin{end}; + svec = [varargin{:}]; + varargin(end) = []; + elseif (ischar (varargin{end})) + if (nargin < 3) + error ("gallery: CLASS argument requires 3 inputs."); + endif + jidx = varargin{end-1}; + svec = [varargin{1:end-1}]; + varargin(end-1) = []; + else + error ("gallery: J must be an integer in the range [0, 2^32-1]"); + endif + + if (! (isnumeric (jidx) && isscalar (jidx) + && jidx == fix (jidx) + && jidx >= 0 && jidx <= 0xFFFFFFFF)) + error ("gallery: J must be an integer in the range [0, 2^32-1]"); + endif + + ## Save and restore random state. Initialization done so that reproducible + ## data is available from gallery depending on the jidx and size vector. + randstate = rand ("state"); + unwind_protect + rand ("state", svec); + A = rand (varargin{:}); + unwind_protect_cleanup + rand ("state", randstate); + end_unwind_protect + +endfunction + function A = wathen (nx, ny, k = 0) ## # WATHEN returns the Wathen matrix. ##