# HG changeset patch # User Rik # Date 1294605681 28800 # Node ID c776f063fefe4741f920f75e1dfdf4e566865c7a # Parent e1edf0ba3bcbe6482d1031742893ee9405cb7e94 Overhaul m-script files to use common variable name between code and documentation. diff --git a/scripts/@ftp/ascii.m b/scripts/@ftp/ascii.m --- a/scripts/@ftp/ascii.m +++ b/scripts/@ftp/ascii.m @@ -19,9 +19,9 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} ascii (@var{f}) ## Put the FTP connection @var{f} into ascii mode. -## @var{f} is an FTP object returned by the ftp function. +## @var{f} is an FTP object returned by the @code{ftp} function. ## @end deftypefn -function ascii (obj) - __ftp_ascii__ (obj.curlhandle); +function ascii (f) + __ftp_ascii__ (f.curlhandle); endfunction diff --git a/scripts/@ftp/binary.m b/scripts/@ftp/binary.m --- a/scripts/@ftp/binary.m +++ b/scripts/@ftp/binary.m @@ -19,9 +19,9 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} binary (@var{f}) ## Put the FTP connection @var{f} into binary mode. -## @var{f} is an FTP object returned by the ftp function. +## @var{f} is an FTP object returned by the @code{ftp} function. ## @end deftypefn -function binary (obj) - __ftp_binary__ (obj.curlhandle); +function binary (f) + __ftp_binary__ (f.curlhandle); endfunction diff --git a/scripts/@ftp/cd.m b/scripts/@ftp/cd.m --- a/scripts/@ftp/cd.m +++ b/scripts/@ftp/cd.m @@ -19,9 +19,9 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} cd (@var{f}, @var{path}) ## Set the remote directory to @var{path} on the FTP connection @var{f}. -## @var{f} is an FTP object returned by the ftp function. +## @var{f} is an FTP object returned by the @code{ftp} function. ## @end deftypefn -function cd (obj, path) - __ftp_cwd__ (obj.curlhandle, path); +function cd (f, path) + __ftp_cwd__ (f.curlhandle, path); endfunction diff --git a/scripts/@ftp/close.m b/scripts/@ftp/close.m --- a/scripts/@ftp/close.m +++ b/scripts/@ftp/close.m @@ -18,10 +18,10 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} close (@var{f}) -## Close the FTP connection represented by given FTP object @var{f}. -## @var{f} is an FTP object returned by the ftp function. +## Close the FTP connection represented by the given FTP object @var{f}. +## @var{f} is an FTP object returned by the @code{ftp} function. ## @end deftypefn -function dir (obj) - __ftp_close__ (obj.curlhandle); +function dir (f) + __ftp_close__ (f.curlhandle); endfunction diff --git a/scripts/@ftp/delete.m b/scripts/@ftp/delete.m --- a/scripts/@ftp/delete.m +++ b/scripts/@ftp/delete.m @@ -19,9 +19,9 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} delete (@var{f}, @var{file}) ## Delete the remote file @var{file}, over the FTP connection @var{f}. -## @var{f} is an FTP object returned by the ftp function. +## @var{f} is an FTP object returned by the @code{ftp} function. ## @end deftypefn -function delete (obj, file) - __ftp_delete__ (obj.curlhandle, file); +function delete (f, file) + __ftp_delete__ (f.curlhandle, file); endfunction diff --git a/scripts/@ftp/dir.m b/scripts/@ftp/dir.m --- a/scripts/@ftp/dir.m +++ b/scripts/@ftp/dir.m @@ -17,15 +17,15 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{lst} =} dir (@var{path}) +## @deftypefn {Function File} {@var{lst} =} dir (@var{f}) ## List the current directory in verbose form for the FTP connection -## @var{f}. @var{f} is an FTP object returned by the ftp function. +## @var{f}. @var{f} is an FTP object returned by the @code{ftp} function. ## @end deftypefn -function lst = dir (obj) +function lst = dir (f) if (nargout == 0) - __ftp_dir__ (obj.curlhandle); + __ftp_dir__ (f.curlhandle); else - lst = __ftp_dir__ (obj.curlhandle); + lst = __ftp_dir__ (f.curlhandle); endif endfunction diff --git a/scripts/@ftp/ftp.m b/scripts/@ftp/ftp.m --- a/scripts/@ftp/ftp.m +++ b/scripts/@ftp/ftp.m @@ -18,7 +18,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{f}} = ftp (@var{host}) -## @deftypefnx {Function File} {@var{f}} = ftp (@var{host}, @var{username}, ## @var{password}) +## @deftypefnx {Function File} {@var{f}} = ftp (@var{host}, @var{username}, @var{password}) ## Connect to the FTP server @var{host} with @var{username} and @var{password}. ## If @var{username} and @var{password} are not specified, user "anonymous" ## with no password is used. The returned FTP object @var{f} represents the diff --git a/scripts/@ftp/mget.m b/scripts/@ftp/mget.m --- a/scripts/@ftp/mget.m +++ b/scripts/@ftp/mget.m @@ -22,7 +22,7 @@ ## @deftypefnx {Function File} {} mget (@dots{}, @var{target}) ## Downloads a remote file @var{file} or directory @var{dir} to the local ## directory on the FTP connection @var{f}. @var{f} is an FTP object -## returned by the ftp function. +## returned by the @code{ftp} function. ## ## The arguments @var{file} and @var{dir} can include wildcards and any ## files or directories on the remote server that match will be downloaded. @@ -32,6 +32,6 @@ ## directory. ## @end deftypefn -function mget (obj, file) - __ftp_mget__ (obj.curlhandle, file); +function mget (f, file) + __ftp_mget__ (f.curlhandle, file); endfunction diff --git a/scripts/@ftp/mkdir.m b/scripts/@ftp/mkdir.m --- a/scripts/@ftp/mkdir.m +++ b/scripts/@ftp/mkdir.m @@ -19,9 +19,9 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} mkdir (@var{f}, @var{path}) ## Create the remote directory @var{path}, over the FTP connection @var{f}. -## @var{f} is an FTP object returned by the ftp function. +## @var{f} is an FTP object returned by the @code{ftp} function. ## @end deftypefn -function mkdir (obj, path) - __ftp_mkdir__ (obj.curlhandle, path); +function mkdir (f, path) + __ftp_mkdir__ (f.curlhandle, path); endfunction diff --git a/scripts/@ftp/mput.m b/scripts/@ftp/mput.m --- a/scripts/@ftp/mput.m +++ b/scripts/@ftp/mput.m @@ -26,10 +26,10 @@ ## files that match the wildcards in @var{file} will be uploaded. ## @end deftypefn -function retval = mput (obj, file) +function retval = mput (f, file) if (nargout == 0) - __ftp_mput__ (obj.curlhandle, file); + __ftp_mput__ (f.curlhandle, file); else - retval = __ftp_mput__ (obj.curlhandle, file); + retval = __ftp_mput__ (f.curlhandle, file); endif endfunction diff --git a/scripts/@ftp/rename.m b/scripts/@ftp/rename.m --- a/scripts/@ftp/rename.m +++ b/scripts/@ftp/rename.m @@ -23,6 +23,6 @@ ## ftp function. ## @end deftypefn -function rename (obj, oldname, newname) - __ftp_rename__ (obj.curlhandle, oldname, newname); +function rename (f, oldname, newname) + __ftp_rename__ (f.curlhandle, oldname, newname); endfunction diff --git a/scripts/@ftp/rmdir.m b/scripts/@ftp/rmdir.m --- a/scripts/@ftp/rmdir.m +++ b/scripts/@ftp/rmdir.m @@ -19,9 +19,9 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} rmdir (@var{f}, @var{path}) ## Remove the remote directory @var{path}, over the FTP connection @var{f}. -## @var{f} is an FTP object returned by the ftp function. +## @var{f} is an FTP object returned by the @code{ftp} function. ## @end deftypefn -function rmdir (obj, path) - __ftp_rmdir__ (obj.curlhandle, path); +function rmdir (f, path) + __ftp_rmdir__ (f.curlhandle, path); endfunction diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,144 @@ +2011-01-09 Rik + + * audio/loadaudio.m, audio/mu2lin.m, audio/saveaudio.m, + general/accumdim.m, general/bitget.m, general/bitset.m, general/del2.m, + general/isequal.m, general/isequalwithequalnans.m, general/logspace.m, + general/repmat.m, general/strerror.m, general/structfun.m, + geometry/delaunayn.m, geometry/dsearchn.m, image/ind2gray.m, + image/ind2rgb.m, image/rgb2ind.m, io/csvread.m, io/csvwrite.m, + linear-algebra/rref.m, linear-algebra/subspace.m, + linear-algebra/trace.m, miscellaneous/dir.m, miscellaneous/dos.m, + miscellaneous/menu.m, miscellaneous/perl.m, miscellaneous/unix.m, + path/savepath.m, plot/allchild.m, plot/diffuse.m, plot/fplot.m, + plot/refreshdata.m, plot/specular.m, plot/subplot.m, + polynomial/polyreduce.m, set/ismember.m, signal/arch_fit.m, + signal/arch_rnd.m, signal/arch_test.m, signal/diffpara.m, + signal/fftfilt.m, signal/filter2.m, signal/sinetone.m, + signal/spectral_xdf.m, signal/stft.m, signal/synthesis.m, + sparse/spfun.m, sparse/spones.m, sparse/spstats.m, sparse/treelayout.m, + sparse/treeplot.m, specfun/isprime.m, + statistics/distributions/expcdf.m, statistics/distributions/expinv.m, + statistics/distributions/exppdf.m, statistics/distributions/exprnd.m, + statistics/distributions/poisscdf.m, + statistics/distributions/poissinv.m, + statistics/distributions/poisspdf.m, + statistics/distributions/poissrnd.m, + statistics/tests/chisquare_test_independence.m, + statistics/tests/cor_test.m, statistics/tests/f_test_regression.m, + statistics/tests/t_test_regression.m, strings/base2dec.m, + strings/dec2base.m, strings/regexptranslate.m, strings/strjust.m, + strings/strmatch.m, time/asctime.m, time/datenum.m: + Use common names for variables in documentation and code. + + * @ftp/ascii.m, @ftp/binary.m, @ftp/cd.m, @ftp/close.m, @ftp/delete.m, + @ftp/dir.m, @ftp/ftp.m, @ftp/mget.m, @ftp/mkdir.m, @ftp/mput.m, + @ftp/rename.m, @ftp/rmdir.m, general/chop.m, geometry/dsearch.m, + signal/spencer.m, specfun/primes.m, time/etime.m: Use common names for + variables in documentation and code. Improve docstring + + * elfun/acot.m, elfun/acoth.m, elfun/acsc.m, elfun/acsch.m, + elfun/asec.m, elfun/asech.m, elfun/cot.m, elfun/coth.m, elfun/csc.m, + elfun/csch.m, elfun/sec.m, elfun/sech.m: Use common names for variables + in documentation and code. Change output variable to 'y' rather than + 'w'. + + * miscellaneous/bunzip2.m, miscellaneous/gunzip.m, + miscellaneous/unpack.m, miscellaneous/untar.m, miscellaneous/unzip.m: + Use common names for variables in documentation and code. Use default + on input argument to simplify input validation. + + * general/accumarray.m: Use common names for variables in + documentation, code and tests. + + * geometry/inpolygon.m: Use common names for variables in + documentation, code and tests. Improve docstring. + + * general/bitcmp.m: Use common names for variables in documentation and + code. Switch tests to %!test blocks rather than %!shared variables and + %!asserts for clarity. + + * general/int2str.m: Switch to input variable name 'n' rather than 'x'. + + * general/isdir.m: Switch to input variable name 'f' rather than 'x'. + Switch output variable to 'retval' rather than 'y'. + + * general/perror.m: Switch to input variable name 'funcname' rather + than 'name'. Use common names for variables in documentation and + code. + + * general/rot90.m: Switch to input variable name 'A' rather than 'x'. + Break very long %!assert line into multiple asserts for readability. + + * general/sortrows.m: Use common names for variables in documentation + and code. Break very long %!assert line into multiple asserts for + readability. + + * geometry/voronoin.m: Switch to input variable name 'options' rather + than 'opt'. + + * help/lookfor.m: Switch to input variable name 'arg2' rather than + 'extra'. + + * image/brighten.m: Switch to input variable name 'arg1' rather than + 'm'. Eliminate CamelCase in output variable 'Rmap'. + + * image/rgb2hsv.m: Switch to variable name 'hsv_map' rather than + 'hsval'. + + * image/saveimage.m: Switch to input variable name 'fname', rather than + 'file'. Use common names for variables in documentation and code. + + * io/strread.m, io/textread.m, io/textscan.m: Switch to input variable + name 'format' rather than 'formatstr' + + * miscellaneous/run.m: Switch to input variable 'script' rather than + 's'. + + * miscellaneous/ver.m: Switch to input variable 'package' rather than + 'pack'. Use default on input argument to simplify input validation. + + * plot/saveas.m: Switch to input variable 'fmt' rather than 'ext'. + Improve docstring. + + * plot/title.m: : Switch to input variable 'string' rather than 'title'. + + * plot/uigetdir.m: Improve docstring. Re-order input validation. + Eliminate unnecessary use of cellfun to compare strings. + + * polynomial/polyder.m, polynomial/polyderiv.m: Switch ouput variable + name 'r' to 'd'. Improve docstring. + + * polynomial/polyint.m: Switch input variable name 'c' to 'p'. + + * signal/fftconv.m: Switch input variable names to 'x','y' instead of + 'a','b' for vectors. + + * signal/fftshift.m, signal/ifftshift.m: Switch input variable name to + 'x' instead of 'v'. + + * sparse/etreeplot.m: Switch input variable name to 'A' rather than + 'tree' for matrix. + + * specfun/factor.m: Use common names for variables in documentation and + code. Uncomment and re-instate test code. + + * statistics/distributions/cauchy_cdf.m, + statistics/distributions/cauchy_inv.m, + statistics/distributions/cauchy_pdf.m, + statistics/distributions/cauchy_rnd.m: Switch to input variables + 'location','scale' rather than 'lambda','sigma'. + + * statistics/tests/manova.m: Switch to input variable 'x' rather than + 'y'. + + * strings/untabify.m: Switch to input variable 'dblank' rather than + 'db'. + + * time/datestr.m: Improve docstring + + * time/weekday.m: Switch to input variable name 'format' rather than + 'form'. Improve docstring. + 2011-01-08 John Hunt * plot/legend.m, plot/private/__plt__.m: legend with more than two diff --git a/scripts/audio/loadaudio.m b/scripts/audio/loadaudio.m --- a/scripts/audio/loadaudio.m +++ b/scripts/audio/loadaudio.m @@ -37,7 +37,7 @@ ## Created: 10 April 1994 ## Adapted-By: jwe -function X = loadaudio (name, ext, bit) +function X = loadaudio (name, ext, bps) if (nargin == 0 || nargin > 3) print_usage (); @@ -48,16 +48,16 @@ endif if (nargin < 3) - bit = 8; - elseif (bit != 8 && bit != 16) - error ("loadaudio: bit must be either 8 or 16"); + bps = 8; + elseif (bps != 8 && bps != 16) + error ("loadaudio: bps must be either 8 or 16"); endif name = [name, ".", ext]; num = fopen (name, "rb"); if (strcmp (ext, "lin") || strcmp (ext, "raw") || strcmp (ext, "pcm")) - if (bit == 8) + if (bps == 8) [Y, c] = fread (num, inf, "uchar"); X = Y - 127; else @@ -71,7 +71,7 @@ if (! isempty (m)) Y(1:m) = []; endif - X = mu2lin (Y, bit); + X = mu2lin (Y, bps); else fclose (num); error ("loadaudio: unsupported extension"); diff --git a/scripts/audio/mu2lin.m b/scripts/audio/mu2lin.m --- a/scripts/audio/mu2lin.m +++ b/scripts/audio/mu2lin.m @@ -18,7 +18,7 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} mu2lin (@var{x}, @var{bps}) +## @deftypefn {Function File} {} mu2lin (@var{x}, @var{n}) ## Convert audio data from mu-law to linear. Mu-law values are 8-bit ## unsigned integers. Linear values use @var{n}-bit signed integers ## or floating point values in the range -1@leq{}y@leq{}1 if @var{n} is 0. If @@ -33,7 +33,7 @@ function y = mu2lin (x, n) if (nargin == 1) - ## COMPATIBILITY -- bps defaults to 8 for Octave, 0 for Matlab + ## COMPATIBILITY -- n defaults to 8 for Octave, 0 for Matlab n = 8; elseif (nargin == 2) if (n != 0 && n != 8 && n != 16) diff --git a/scripts/audio/saveaudio.m b/scripts/audio/saveaudio.m --- a/scripts/audio/saveaudio.m +++ b/scripts/audio/saveaudio.m @@ -31,7 +31,7 @@ ## Created: 5 September 1994 ## Adapted-By: jwe -function saveaudio (name, X, ext, bit) +function saveaudio (name, x, ext, bps) if (nargin < 2 || nargin > 4) print_usage (); @@ -42,15 +42,15 @@ endif if (nargin < 4) - bit = 8; - elseif (bit != 8 && bit != 16) - error ("saveaudio: bit must be either 8 or 16"); + bps = 8; + elseif (bps != 8 && bps != 16) + error ("saveaudio: bps must be either 8 or 16"); endif - [nr, nc] = size (X); + [nr, nc] = size (x); if (nc != 1) if (nr == 1) - X = X'; + x = x'; nr = nc; else error ("saveaudio: X must be a vector"); @@ -60,25 +60,25 @@ num = fopen ([name, ".", ext], "wb"); if (strcmp (ext, "lin") || strcmp (ext, "raw")) - if (bit == 8) - ld = max (abs (X)); + if (bps == 8) + ld = max (abs (x)); if (ld > 127) # convert 16 to 8 bit if (ld < 16384) sc = 64 / ld; else sc = 1 / 256; endif - X = fix (X * sc); + x = fix (x * sc); endif - X = X + 127; - c = fwrite (num, X, "uchar"); + x = x + 127; + c = fwrite (num, x, "uchar"); else - c = fwrite (num, X, "short"); + c = fwrite (num, x, "short"); endif elseif (strcmp (ext, "mu") || strcmp (ext, "au") || strcmp (ext, "snd") || strcmp (ext, "ul")) - Y = lin2mu (X); - c = fwrite (num, Y, "uchar"); + y = lin2mu (x); + c = fwrite (num, y, "uchar"); else fclose (num); error ("saveaudio: unsupported extension"); diff --git a/scripts/elfun/acot.m b/scripts/elfun/acot.m --- a/scripts/elfun/acot.m +++ b/scripts/elfun/acot.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = acot (z) +function y = acot (x) if (nargin != 1) print_usage (); endif - w = atan (1./z); + y = atan (1./x); endfunction diff --git a/scripts/elfun/acoth.m b/scripts/elfun/acoth.m --- a/scripts/elfun/acoth.m +++ b/scripts/elfun/acoth.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = acoth (z) +function y = acoth (x) if (nargin != 1) print_usage (); endif - w = atanh (1 ./ z); + y = atanh (1 ./ x); endfunction diff --git a/scripts/elfun/acsc.m b/scripts/elfun/acsc.m --- a/scripts/elfun/acsc.m +++ b/scripts/elfun/acsc.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = acsc (z) +function y = acsc (x) if (nargin != 1) print_usage (); endif - w = asin (1 ./ z); + y = asin (1 ./ x); endfunction diff --git a/scripts/elfun/acsch.m b/scripts/elfun/acsch.m --- a/scripts/elfun/acsch.m +++ b/scripts/elfun/acsch.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = acsch (z) +function y = acsch (x) if (nargin != 1) print_usage (); endif - w = asinh (1 ./ z); + y = asinh (1 ./ x); endfunction diff --git a/scripts/elfun/asec.m b/scripts/elfun/asec.m --- a/scripts/elfun/asec.m +++ b/scripts/elfun/asec.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = asec (z) +function y = asec (x) if (nargin != 1) print_usage (); endif - w = acos (1 ./ z); + y = acos (1 ./ x); endfunction diff --git a/scripts/elfun/asech.m b/scripts/elfun/asech.m --- a/scripts/elfun/asech.m +++ b/scripts/elfun/asech.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = asech (z) +function y = asech (x) if (nargin != 1) print_usage (); endif - w = acosh (1 ./ z); + y = acosh (1 ./ x); endfunction diff --git a/scripts/elfun/cot.m b/scripts/elfun/cot.m --- a/scripts/elfun/cot.m +++ b/scripts/elfun/cot.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = cot (z) +function y = cot (x) if (nargin != 1) print_usage (); endif - w = 1 ./ tan(z); + y = 1 ./ tan(x); endfunction diff --git a/scripts/elfun/coth.m b/scripts/elfun/coth.m --- a/scripts/elfun/coth.m +++ b/scripts/elfun/coth.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = coth (z) +function y = coth (x) if (nargin != 1) print_usage (); endif - w = 1 ./ tanh (z); + y = 1 ./ tanh (x); endfunction diff --git a/scripts/elfun/csc.m b/scripts/elfun/csc.m --- a/scripts/elfun/csc.m +++ b/scripts/elfun/csc.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = csc (z) +function y = csc (x) if (nargin != 1) print_usage (); endif - w = 1 ./ sin(z); + y = 1 ./ sin(x); endfunction diff --git a/scripts/elfun/csch.m b/scripts/elfun/csch.m --- a/scripts/elfun/csch.m +++ b/scripts/elfun/csch.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = csch (z) +function y = csch (x) if (nargin != 1) print_usage (); endif - w = 1 ./ sinh(z); + y = 1 ./ sinh(x); endfunction diff --git a/scripts/elfun/sec.m b/scripts/elfun/sec.m --- a/scripts/elfun/sec.m +++ b/scripts/elfun/sec.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = sec (z) +function y = sec (x) if (nargin != 1) print_usage (); endif - w = 1 ./ cos(z); + y = 1 ./ cos(x); endfunction diff --git a/scripts/elfun/sech.m b/scripts/elfun/sech.m --- a/scripts/elfun/sech.m +++ b/scripts/elfun/sech.m @@ -25,13 +25,13 @@ ## Author: jwe -function w = sech (z) +function y = sech (x) if (nargin != 1) print_usage (); endif - w = 1 ./ cosh(z); + y = 1 ./ cosh(x); endfunction diff --git a/scripts/general/accumarray.m b/scripts/general/accumarray.m --- a/scripts/general/accumarray.m +++ b/scripts/general/accumarray.m @@ -64,7 +64,7 @@ ## compute the results in a vectorized manner. ## @end deftypefn -function A = accumarray (subs, val, sz = [], func = [], fillval = [], isspar = []) +function A = accumarray (subs, vals, sz = [], func = [], fillval = [], issparse = []) if (nargin < 2 || nargin > 6) print_usage (); @@ -84,11 +84,11 @@ fillval = 0; endif - if (isempty (isspar)) - isspar = false; + if (isempty (issparse)) + issparse = false; endif - if (isspar) + if (issparse) ## Sparse case. Avoid linearizing the subscripts, because it could overflow. @@ -108,8 +108,8 @@ error ("accumarray: in the sparse case, needs 1 or 2 subscripts"); endif - if (isnumeric (val) || islogical (val)) - vals = double (val); + if (isnumeric (vals) || islogical (vals)) + vals = double (vals); else error ("accumarray: in the sparse case, values must be numeric or logical"); endif @@ -126,7 +126,7 @@ jdx = find (any (diff (subs, 1, 1), 2)); jdx = [jdx; n]; - val = cellfun (func, mat2cell (val(:)(idx), diff ([0; jdx]))); + vals = cellfun (func, mat2cell (vals(:)(idx), diff ([0; jdx]))); subs = subs(jdx, :); mode = "unique"; else @@ -135,9 +135,9 @@ ## Form the sparse matrix. if (isempty (sz)) - A = sparse (subs(:,1), subs(:,2), val, mode); + A = sparse (subs(:,1), subs(:,2), vals, mode); elseif (length (sz) == 2) - A = sparse (subs(:,1), subs(:,2), val, sz(1), sz(2), mode); + A = sparse (subs(:,1), subs(:,2), vals, sz(1), sz(2), mode); else error ("accumarray: dimensions mismatch") endif @@ -173,9 +173,9 @@ if (isempty (func) || func == @sum) ## Fast summation. if (isempty (sz)) - A = __accumarray_sum__ (subs, val); + A = __accumarray_sum__ (subs, vals); else - A = __accumarray_sum__ (subs, val, prod (sz)); + A = __accumarray_sum__ (subs, vals, prod (sz)); ## set proper shape. A = reshape (A, sz); endif @@ -189,11 +189,11 @@ elseif (func == @max) ## Fast maximization. - if (isinteger (val)) - zero = intmin (class (val)); - elseif (islogical (val)) + if (isinteger (vals)) + zero = intmin (class (vals)); + elseif (islogical (vals)) zero = false; - elseif (fillval == 0 && all (val(:) >= 0)) + elseif (fillval == 0 && all (vals(:) >= 0)) ## This is a common case - fillval is zero, all numbers nonegative. zero = 0; else @@ -201,9 +201,9 @@ endif if (isempty (sz)) - A = __accumarray_max__ (subs, val, zero); + A = __accumarray_max__ (subs, vals, zero); else - A = __accumarray_max__ (subs, val, zero, prod (sz)); + A = __accumarray_max__ (subs, vals, zero, prod (sz)); A = reshape (A, sz); endif @@ -215,18 +215,18 @@ elseif (func == @min) ## Fast minimization. - if (isinteger (val)) - zero = intmax (class (val)); - elseif (islogical (val)) + if (isinteger (vals)) + zero = intmax (class (vals)); + elseif (islogical (vals)) zero = true; else zero = NaN; # Neutral value. endif if (isempty (sz)) - A = __accumarray_min__ (subs, val, zero); + A = __accumarray_min__ (subs, vals, zero); else - A = __accumarray_min__ (subs, val, zero, prod (sz)); + A = __accumarray_min__ (subs, vals, zero, prod (sz)); A = reshape (A, sz); endif @@ -239,10 +239,10 @@ ## The general case. Reduce values. n = rows (subs); - if (numel (val) == 1) - val = val(ones (1, n), 1); + if (numel (vals) == 1) + vals = vals(ones (1, n), 1); else - val = val(:); + vals = vals(:); endif ## Sort indices. @@ -250,26 +250,26 @@ ## Identify runs. jdx = find (subs(1:n-1) != subs(2:n)); jdx = [jdx; n]; - val = mat2cell (val(idx), diff ([0; jdx])); + vals = mat2cell (vals(idx), diff ([0; jdx])); ## Optimize the case when function is @(x) {x}, i.e. we just want to ## collect the values to cells. persistent simple_cell_str = func2str (@(x) {x}); if (! strcmp (func2str (func), simple_cell_str)) - val = cellfun (func, val); + vals = cellfun (func, vals); endif subs = subs(jdx); ## Construct matrix of fillvals. - if (iscell (val)) + if (iscell (vals)) A = cell (sz); elseif (fillval == 0) - A = zeros (sz, class (val)); + A = zeros (sz, class (vals)); else A = repmat (fillval, sz); endif ## Set the reduced values. - A(subs) = val; + A(subs) = vals; endif endif endfunction @@ -289,21 +289,21 @@ %! assert (A{2},[102;104]) %!test %! subs = ceil (rand (2000, 3)*10); -%! val = rand (2000, 1); -%! assert (accumarray (subs, val, [], @max), accumarray (subs, val, [], @(x) max (x))); +%! vals = rand (2000, 1); +%! assert (accumarray (subs, vals, [], @max), accumarray (subs, vals, [], @(x) max (x))); %!test %! subs = ceil (rand (2000, 1)*100); -%! val = rand (2000, 1); -%! assert (accumarray (subs, val, [100, 1], @min, NaN), accumarray (subs, val, [100, 1], @(x) min (x), NaN)); +%! vals = rand (2000, 1); +%! assert (accumarray (subs, vals, [100, 1], @min, NaN), accumarray (subs, vals, [100, 1], @(x) min (x), NaN)); %!test %! subs = ceil (rand (2000, 2)*30); %! subsc = num2cell (subs, 1); -%! val = rand (2000, 1); -%! assert (accumarray (subsc, val, [], [], 0, true), accumarray (subs, val, [], [], 0, true)); +%! vals = rand (2000, 1); +%! assert (accumarray (subsc, vals, [], [], 0, true), accumarray (subs, vals, [], [], 0, true)); %!test %! subs = ceil (rand (2000, 3)*10); %! subsc = num2cell (subs, 1); -%! val = rand (2000, 1); -%! assert (accumarray (subsc, val, [], @max), accumarray (subs, val, [], @max)); +%! vals = rand (2000, 1); +%! assert (accumarray (subsc, vals, [], @max), accumarray (subs, vals, [], @max)); diff --git a/scripts/general/accumdim.m b/scripts/general/accumdim.m --- a/scripts/general/accumdim.m +++ b/scripts/general/accumdim.m @@ -52,7 +52,7 @@ ## @seealso{accumarray} ## @end deftypefn -function A = accumdim (subs, val, dim, n = 0, func = [], fillval = 0) +function A = accumdim (subs, vals, dim, n = 0, func = [], fillval = 0) if (nargin < 2 || nargin > 5) print_usage (); @@ -75,7 +75,7 @@ endif endif - sz = size (val); + sz = size (vals); if (nargin < 3) [~, dim] = max (sz != 1); # first non-singleton dim @@ -88,7 +88,7 @@ if (isempty (func) || func == @sum) ## Fast summation case. - A = __accumdim_sum__ (subs, val, dim, n); + A = __accumdim_sum__ (subs, vals, dim, n); ## Fill in nonzero fill value if (fillval != 0) @@ -113,28 +113,28 @@ szc{dim} = diff ([0; jdx]); subsc = {':'}(ones (1, length (sz))); subsc{dim} = idx; - val = mat2cell (val(subsc{:}), szc{:}); + vals = mat2cell (vals(subsc{:}), szc{:}); ## Apply reductions. Special case min, max. if (func == @min || func == @max) - val = cellfun (func, val, {[]}, {dim}, "uniformoutput", false); + vals = cellfun (func, vals, {[]}, {dim}, "uniformoutput", false); else - val = cellfun (func, val, {dim}, "uniformoutput", false); + vals = cellfun (func, vals, {dim}, "uniformoutput", false); endif subs = subs(jdx); ## Concatenate reduced slices. - val = cat (dim, val{:}); + vals = cat (dim, vals{:}); ## Construct matrix of fillvals. if (fillval == 0) - A = zeros (sz, class (val)); + A = zeros (sz, class (vals)); else A = repmat (fillval, sz); endif ## Set the reduced values. subsc{dim} = subs; - A(subsc{:}) = val; + A(subsc{:}) = vals; endfunction diff --git a/scripts/general/bitcmp.m b/scripts/general/bitcmp.m --- a/scripts/general/bitcmp.m +++ b/scripts/general/bitcmp.m @@ -17,8 +17,8 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} bitcmp (@var{a}, @var{k}) -## Return the @var{k}-bit complement of integers in @var{a}. If +## @deftypefn {Function File} {} bitcmp (@var{A}, @var{k}) +## Return the @var{k}-bit complement of integers in @var{A}. If ## @var{k} is omitted @code{k = log2 (bitmax) + 1} is assumed. ## ## @example @@ -34,88 +34,90 @@ ## @seealso{bitand, bitor, bitxor, bitset, bitget, bitcmp, bitshift, bitmax} ## @end deftypefn -## Liberally based of the version by Kai Habel from octave-forge +## Liberally based on the version by Kai Habel from octave-forge -function x = bitcmp (a, n) +function C = bitcmp (A, k) if (nargin < 1 || nargin > 2) print_usage (); endif - if (nargin == 2 && (! isscalar (n) || (floor (n) != n))) + if (nargin == 2 && (! isscalar (k) || (floor (k) != k))) error ("bitcmp: k must be a scalar integer"); endif - if (isa (a, "double")) + if (isa (A, "double")) bmax = bitmax; amax = ceil (log2 (bmax)); else - if (isa (a, "uint8")) + if (isa (A, "uint8")) amax = 8; - elseif (isa (a, "uint16")) + elseif (isa (A, "uint16")) amax = 16; - elseif (isa (a, "uint32")) + elseif (isa (A, "uint32")) amax = 32; - elseif (isa (a, "uint64")) + elseif (isa (A, "uint64")) amax = 64; - elseif (isa (a, "int8")) + elseif (isa (A, "int8")) amax = 8; - elseif (isa (a, "int16")) + elseif (isa (A, "int16")) amax = 16; - elseif (isa (a, "int32")) + elseif (isa (A, "int32")) amax = 32; - elseif (isa (a, "int64")) + elseif (isa (A, "int64")) amax = 64; else - error ("bitcmp: invalid class %s", class (a)); + error ("bitcmp: invalid class %s", class (A)); endif - bmax = intmax (class (a)); + bmax = intmax (class (A)); endif - if (nargin == 1 || n == amax) - x = bitxor (a, bmax); + if (nargin == 1 || k == amax) + C = bitxor (A, bmax); else - m = double (n); + m = double (k); if (any (m < 1) || any (m > amax)) - error ("bitcmp: n must be in the range [1,%d]", amax); + error ("bitcmp: k must be in the range [1,%d]", amax); endif - mask = bitshift (bmax, n - amax); - x = bitxor (bitand (a, mask), mask); + mask = bitshift (bmax, k - amax); + C = bitxor (bitand (A, mask), mask); endif endfunction -%!shared Amax,Bmax,A + +%!test %! Amax=53; %! Bmax = bitmax; %! A = bitshift(Bmax,-2); -%!assert(bitcmp(A,Amax),bitor(bitshift(1,Amax-1),bitshift(1,Amax-2))); -%!assert(bitcmp(A,Amax-1),bitshift(1,Amax-2)); -%!assert(bitcmp(A,Amax-2),0); -%!shared Amax,Bmax,A +%! assert(bitcmp(A,Amax),bitor(bitshift(1,Amax-1),bitshift(1,Amax-2))); +%! assert(bitcmp(A,Amax-1),bitshift(1,Amax-2)); +%! assert(bitcmp(A,Amax-2),0); +%!test %! Amax=8; %! Bmax = intmax('uint8'); %! A = bitshift(Bmax,-2); -%!assert(bitcmp(A,Amax),bitor(bitshift(uint8(1),Amax-1),bitshift(uint8(1),Amax-2))); -%!assert(bitcmp(A,Amax-1),bitshift(uint8(1),Amax-2)); -%!assert(bitcmp(A,Amax-2),uint8(0)); -%!shared Amax,Bmax,A +%! assert(bitcmp(A,Amax),bitor(bitshift(uint8(1),Amax-1),bitshift(uint8(1),Amax-2))); +%! assert(bitcmp(A,Amax-1),bitshift(uint8(1),Amax-2)); +%! assert(bitcmp(A,Amax-2),uint8(0)); +%!test %! Amax=16; %! Bmax = intmax('uint16'); %! A = bitshift(Bmax,-2); -%!assert(bitcmp(A,Amax),bitor(bitshift(uint16(1),Amax-1),bitshift(uint16(1),Amax-2))); -%!assert(bitcmp(A,Amax-1),bitshift(uint16(1),Amax-2)); -%!assert(bitcmp(A,Amax-2),uint16(0)); -%!shared Amax,Bmax,A +%! assert(bitcmp(A,Amax),bitor(bitshift(uint16(1),Amax-1),bitshift(uint16(1),Amax-2))); +%! assert(bitcmp(A,Amax-1),bitshift(uint16(1),Amax-2)); +%! assert(bitcmp(A,Amax-2),uint16(0)); +%!test %! Amax=32; %! Bmax = intmax('uint32'); %! A = bitshift(Bmax,-2); -%!assert(bitcmp(A,Amax),bitor(bitshift(uint32(1),Amax-1),bitshift(uint32(1),Amax-2))); -%!assert(bitcmp(A,Amax-1),bitshift(uint32(1),Amax-2)); -%!assert(bitcmp(A,Amax-2),uint32(0)); -%!shared Amax,Bmax,A +%! assert(bitcmp(A,Amax),bitor(bitshift(uint32(1),Amax-1),bitshift(uint32(1),Amax-2))); +%! assert(bitcmp(A,Amax-1),bitshift(uint32(1),Amax-2)); +%! assert(bitcmp(A,Amax-2),uint32(0)); +%!test %! Amax=64; %! Bmax = intmax('uint64'); %! A = bitshift(Bmax,-2); -%!assert(bitcmp(A,Amax),bitor(bitshift(uint64(1),Amax-1),bitshift(uint64(1),Amax-2))); -%!assert(bitcmp(A,Amax-1),bitshift(uint64(1),Amax-2)); -%!assert(bitcmp(A,Amax-2),uint64(0)); +%! assert(bitcmp(A,Amax),bitor(bitshift(uint64(1),Amax-1),bitshift(uint64(1),Amax-2))); +%! assert(bitcmp(A,Amax-1),bitshift(uint64(1),Amax-2)); +%! assert(bitcmp(A,Amax-2),uint64(0)); + diff --git a/scripts/general/bitget.m b/scripts/general/bitget.m --- a/scripts/general/bitget.m +++ b/scripts/general/bitget.m @@ -17,8 +17,8 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{X} =} bitget (@var{a},@var{n}) -## Return the status of bit(s) @var{n} of unsigned integers in @var{a} +## @deftypefn {Function File} {@var{c} =} bitget (@var{A},@var{n}) +## Return the status of bit(s) @var{n} of unsigned integers in @var{A} ## the lowest significant bit is @var{n} = 1. ## ## @example @@ -32,7 +32,7 @@ ## Liberally based of the version by Kai Habel from octave-forge -function X = bitget (A, n) +function C = bitget (A, n) if (nargin != 2) print_usage (); @@ -76,5 +76,6 @@ error ("bitget: n must be in the range [1,%d]", Amax); endif - X = bitand (A, bitshift (_conv (1), uint8 (n) - uint8 (1))) != _conv (0); + C = bitand (A, bitshift (_conv (1), uint8 (n) - uint8 (1))) != _conv (0); + endfunction diff --git a/scripts/general/bitset.m b/scripts/general/bitset.m --- a/scripts/general/bitset.m +++ b/scripts/general/bitset.m @@ -17,10 +17,10 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{x} =} bitset (@var{a}, @var{n}) -## @deftypefnx {Function File} {@var{x} =} bitset (@var{a}, @var{n}, @var{v}) -## Set or reset bit(s) @var{n} of unsigned integers in @var{a}. -## @var{v} = 0 resets and @var{v} = 1 sets the bits. +## @deftypefn {Function File} {@var{C} =} bitset (@var{A}, @var{n}) +## @deftypefnx {Function File} {@var{C} =} bitset (@var{A}, @var{n}, @var{val}) +## Set or reset bit(s) @var{n} of unsigned integers in @var{A}. +## @var{val} = 0 resets and @var{val} = 1 sets the bits. ## The lowest significant bit is: @var{n} = 1 ## ## @example @@ -32,16 +32,16 @@ ## @seealso{bitand, bitor, bitxor, bitget, bitcmp, bitshift, bitmax} ## @end deftypefn -## Liberally based of the version by Kai Habel from octave-forge +## Liberally based on the version by Kai Habel from octave-forge -function X = bitset (A, n, value) +function C = bitset (A, n, val) if (nargin < 2 || nargin > 3) print_usage (); endif if (nargin == 2) - value = 1; + val = 1; endif if (isa (A, "double")) @@ -85,10 +85,10 @@ endif mask = bitshift (_conv (1), uint8 (n) - uint8 (1)); - X = bitxor (A, bitand (A, mask)); + C = bitxor (A, bitand (A, mask)); - if (value) - X = bitor (A, mask); + if (val) + C = bitor (A, mask); endif endfunction diff --git a/scripts/general/chop.m b/scripts/general/chop.m --- a/scripts/general/chop.m +++ b/scripts/general/chop.m @@ -17,9 +17,9 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} chop (@var{x}, @var{d}, @var{u}) -## Truncate elements of @var{x} to @var{d} digits such that the -## resulting digits are exactly divisible by @var{u}. If @var{u} is not +## @deftypefn {Function File} {} chop (@var{x}, @var{ndigits}, @var{base}) +## Truncate elements of @var{x} to a length of @var{ndigits} such that the +## resulting numbers are exactly divisible by @var{base}. If @var{base} is not ## specified it defaults to 10. ## ## @example @@ -32,7 +32,7 @@ ## @end example ## @end deftypefn -function retval = chop (x, digits, units = 10) +function retval = chop (x, ndigits, base = 10) if (nargin == 2 || nargin == 3) tmp = abs (x); @@ -50,16 +50,16 @@ ## produces an integer that contains the digits we want to keep. ## Multiplying by deflate puts the decimal back where it belngs. ## - ## Further scaling and rounding with the units factor produces a - ## value with digits exactly divisible by units. We skip that step - ## unless units was explicitly provided. + ## Further scaling and rounding with the base factor produces a + ## value with ndigits exactly divisible by base. We skip that step + ## unless base was explicitly provided. - inflate = 10 .^ (digits - tmp); - deflate = 10 .^ (tmp - digits); + inflate = 10 .^ (ndigits - tmp); + deflate = 10 .^ (tmp - ndigits); if (nargin == 2) retval = deflate .* round (x .* inflate); else - retval = units .* deflate .* round (round (x .* inflate) ./ units); + retval = base .* deflate .* round (round (x .* inflate) ./ base); endif else print_usage (); @@ -67,6 +67,7 @@ endfunction + %!assert (chop (e, 3), 2.72) %!assert (chop (e, 4), 2.718) %!assert (chop (e, 4, 5), 2.72) diff --git a/scripts/general/del2.m b/scripts/general/del2.m --- a/scripts/general/del2.m +++ b/scripts/general/del2.m @@ -18,9 +18,9 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{d} =} del2 (@var{m}) -## @deftypefnx {Function File} {@var{d} =} del2 (@var{m}, @var{h}) -## @deftypefnx {Function File} {@var{d} =} del2 (@var{m}, @var{dx}, @var{dy}, @dots{}) +## @deftypefn {Function File} {@var{d} =} del2 (@var{M}) +## @deftypefnx {Function File} {@var{d} =} del2 (@var{M}, @var{h}) +## @deftypefnx {Function File} {@var{d} =} del2 (@var{M}, @var{dx}, @var{dy}, @dots{}) ## ## Calculate the discrete Laplace ## @tex @@ -29,7 +29,7 @@ ## @ifnottex ## operator. ## @end ifnottex -## For a 2-dimensional matrix @var{m} this is defined as +## For a 2-dimensional matrix @var{M} this is defined as ## @tex ## $$d = {1 \over 4} \left( {d^2 \over dx^2} M(x,y) + {d^2 \over dy^2} M(x,y) \right)$$ ## @end tex @@ -53,7 +53,7 @@ ## @var{dy}, etc. A scalar spacing argument defines equidistant spacing, ## whereas a vector argument can be used to specify variable spacing. The ## length of the spacing vectors must match the respective dimension of -## @var{m}. The default spacing value is 1. +## @var{M}. The default spacing value is 1. ## ## At least 3 data points are needed for each dimension. Boundary points are ## calculated from the linear extrapolation of interior points. diff --git a/scripts/general/int2str.m b/scripts/general/int2str.m --- a/scripts/general/int2str.m +++ b/scripts/general/int2str.m @@ -48,27 +48,27 @@ ## Author: jwe -function retval = int2str (x) +function retval = int2str (n) if (nargin == 1) - x = round (real(x)); - sz = size(x); - nd = ndims (x); - nc = columns (x); + n = round (real(n)); + sz = size(n); + nd = ndims (n); + nc = columns (n); if (nc > 1) idx = cell (); for i = 1:nd idx{i} = 1:sz(i); endfor idx(2) = 1; - ifmt = get_fmt (x(idx{:}), 0); + ifmt = get_fmt (n(idx{:}), 0); idx(2) = 2:sz(2); - rfmt = get_fmt (x(idx{:}), 2); + rfmt = get_fmt (n(idx{:}), 2); fmt = cstrcat (ifmt, repmat (rfmt, 1, nc-1), "\n"); else - fmt = cstrcat (get_fmt (x, 0), "\n"); + fmt = cstrcat (get_fmt (n, 0), "\n"); endif - tmp = sprintf (fmt, permute (x, [2, 1, 3 : nd])); + tmp = sprintf (fmt, permute (n, [2, 1, 3 : nd])); tmp(end) = ""; retval = char (strsplit (tmp, "\n")); else diff --git a/scripts/general/isdir.m b/scripts/general/isdir.m --- a/scripts/general/isdir.m +++ b/scripts/general/isdir.m @@ -22,10 +22,10 @@ ## @seealso{is_absolute_filename, is_rooted_relative_filename} ## @end deftypefn -function t = isdir (x) +function retval = isdir (f) if (nargin == 1) ## Exist returns an integer but isdir should return a logical. - t = exist (x, "dir") == 7; + retval = (exist (f, "dir") == 7); else print_usage ("isdir"); endif diff --git a/scripts/general/isequal.m b/scripts/general/isequal.m --- a/scripts/general/isequal.m +++ b/scripts/general/isequal.m @@ -22,10 +22,10 @@ ## @seealso{isequalwithequalnans} ## @end deftypefn -function retval = isequal (x, varargin) +function retval = isequal (x1, varargin) if (nargin > 1) - retval = __isequal__ (false, x, varargin{:}); + retval = __isequal__ (false, x1, varargin{:}); else print_usage (); endif diff --git a/scripts/general/isequalwithequalnans.m b/scripts/general/isequalwithequalnans.m --- a/scripts/general/isequalwithequalnans.m +++ b/scripts/general/isequalwithequalnans.m @@ -23,10 +23,10 @@ ## @seealso{isequal} ## @end deftypefn -function retval = isequalwithequalnans (x, varargin) +function retval = isequalwithequalnans (x1, varargin) if (nargin > 1) - retval = __isequal__ (true, x, varargin{:}); + retval = __isequal__ (true, x1, varargin{:}); else print_usage (); endif diff --git a/scripts/general/logspace.m b/scripts/general/logspace.m --- a/scripts/general/logspace.m +++ b/scripts/general/logspace.m @@ -61,7 +61,7 @@ ## Author: jwe -function retval = logspace (x1, x2, n) +function retval = logspace (base, limit, n) if (nargin == 2) npoints = 50; @@ -75,12 +75,11 @@ print_usage (); endif - if (length (x1) == 1 && length (x2) == 1) - x2_tmp = x2; - if (x2 == pi) - x2_tmp = log10 (pi); + if (length (base) == 1 && length (limit) == 1) + if (limit == pi) + limit = log10 (pi); endif - retval = 10 .^ (linspace (x1, x2_tmp, npoints)); + retval = 10 .^ (linspace (base, limit, npoints)); else error ("logspace: arguments must be scalars"); endif diff --git a/scripts/general/perror.m b/scripts/general/perror.m --- a/scripts/general/perror.m +++ b/scripts/general/perror.m @@ -18,8 +18,8 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} perror (@var{name}, @var{num}) -## Print the error message for function @var{name} corresponding to the +## @deftypefn {Function File} {} perror (@var{funcname}, @var{num}) +## Print the error message for function @var{funcname} corresponding to the ## error number @var{num}. This function is intended to be used to print ## useful error messages for those functions that return numeric error ## codes. @@ -28,12 +28,12 @@ ## Author: jwe -function perror (name, err) +function perror (funcname, num) if (nargin != 2) print_usage (); else - printf (strerror (name, err)); + printf (strerror (funcname, num)); endif endfunction diff --git a/scripts/general/repmat.m b/scripts/general/repmat.m --- a/scripts/general/repmat.m +++ b/scripts/general/repmat.m @@ -30,7 +30,7 @@ ## Author: Paul Kienzle ## Created: July 2000 -function x = repmat (a, m, n) +function x = repmat (A, m, n) if (nargin < 2 || nargin > 3) print_usage (); @@ -59,27 +59,27 @@ idx = max (idx, 0); endif - if (numel (a) == 1) + if (numel (A) == 1) ## optimize the scalar fill case. if (any (idx == 0)) - x = resize (a, idx); + x = resize (A, idx); else - x(1:prod (idx)) = a; + x(1:prod (idx)) = A; x = reshape (x, idx); endif - elseif (ndims (a) == 2 && length (idx) < 3) - if (issparse (a)) - x = kron (ones (idx), a); + elseif (ndims (A) == 2 && length (idx) < 3) + if (issparse (A)) + x = kron (ones (idx), A); else ## indexing is now faster, so we use it rather than kron. - m = rows (a); n = columns (a); + m = rows (A); n = columns (A); p = idx(1); q = idx(2); - x = reshape (a, m, 1, n, 1); + x = reshape (A, m, 1, n, 1); x = x(:, ones (1, p), :, ones (1, q)); x = reshape (x, m*p, n*q); endif else - aidx = size (a); + aidx = size (A); ## ensure matching size idx(end+1:length (aidx)) = 1; aidx(end+1:length (idx)) = 1; @@ -92,8 +92,8 @@ aaidx = aidx; # add singleton dims aaidx(2,:) = 1; - a = reshape (a, aaidx(:)); - x = reshape (a (cidx{:}), idx .* aidx); + A = reshape (A, aaidx(:)); + x = reshape (A (cidx{:}), idx .* aidx); endif endfunction diff --git a/scripts/general/rot90.m b/scripts/general/rot90.m --- a/scripts/general/rot90.m +++ b/scripts/general/rot90.m @@ -18,11 +18,11 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} rot90 (@var{x}, @var{n}) -## Return a copy of @var{x} with the elements rotated counterclockwise in +## @deftypefn {Function File} {} rot90 (@var{A}, @var{k}) +## Return a copy of @var{A} with the elements rotated counterclockwise in ## 90-degree increments. The second argument is optional, and specifies ## how many 90-degree rotations are to be applied (the default value is 1). -## Negative values of @var{n} rotate the matrix in a clockwise direction. +## Negative values of @var{k} rotate the matrix in a clockwise direction. ## For example, ## ## @example @@ -53,14 +53,14 @@ ## Author: jwe -function y = rot90 (x, k) +function B = rot90 (A, k) if (nargin == 1 || nargin == 2) if (nargin < 2) k = 1; endif - if (ndims (x) > 2) + if (ndims (A) > 2) error ("rot90: Only works with 2-D arrays"); endif @@ -75,13 +75,13 @@ endif if (k == 0) - y = x; + B = A; elseif (k == 1) - y = flipud (x.'); + B = flipud (A.'); elseif (k == 2) - y = flipud (fliplr (x)); + B = flipud (fliplr (A)); elseif (k == 3) - y = (flipud (x)).'; + B = (flipud (A)).'; else error ("rot90: internal error!"); endif @@ -92,19 +92,19 @@ endfunction %!test -%! x1 = [1, 2; -%! 3, 4]; -%! x2 = [2, 4; -%! 1, 3]; -%! x3 = [4, 3; -%! 2, 1]; -%! x4 = [3, 1; -%! 4, 2]; +%! x1 = [1, 2; 3, 4]; +%! x2 = [2, 4; 1, 3]; +%! x3 = [4, 3; 2, 1]; +%! x4 = [3, 1; 4, 2]; %! -%! assert((rot90 (x1)== x2 && rot90 (x1, 2) == x3 && rot90 (x1, 3) == x4 -%! && rot90 (x1, 4) == x1 && rot90 (x1, 5) == x2 && rot90 (x1, -1) == x4)); +%! assert(rot90 (x1) == x2); +%! assert(rot90 (x1, 2) == x3); +%! assert(rot90 (x1, 3) == x4); +%! assert(rot90 (x1, 4) == x1); +%! assert(rot90 (x1, 5) == x2); +%! assert(rot90 (x1, -1) == x4); +%% Test input validation %!error rot90 (); - %!error rot90 (1, 2, 3); diff --git a/scripts/general/sortrows.m b/scripts/general/sortrows.m --- a/scripts/general/sortrows.m +++ b/scripts/general/sortrows.m @@ -18,8 +18,8 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} sortrows (@var{a}, @var{c}) -## Sort the rows of the matrix @var{a} according to the order of the +## @deftypefn {Function File} {} sortrows (@var{A}, @var{c}) +## Sort the rows of the matrix @var{A} according to the order of the ## columns specified in @var{c}. If @var{c} is omitted, a ## lexicographical sort is used. By default ascending order is used ## however if elements of @var{c} are negative then the corresponding @@ -29,33 +29,33 @@ ## Author: Daniel Calvelo, Paul Kienzle ## Adapted-by: jwe -function [s, i] = sortrows (m, c) +function [s, i] = sortrows (A, c) default_mode = "ascend"; other_mode = "descend"; - if (issparse (m)) + if (issparse (A)) ## FIXME -- eliminate this case once __sort_rows_idx__ is fixed to ## handle sparse matrices. if (nargin == 1) - i = sort_rows_idx_generic (default_mode, other_mode, m); + i = sort_rows_idx_generic (default_mode, other_mode, A); else - i = sort_rows_idx_generic (default_mode, other_mode, m, c); + i = sort_rows_idx_generic (default_mode, other_mode, A, c); endif elseif (nargin == 1) - i = __sort_rows_idx__ (m, default_mode); + i = __sort_rows_idx__ (A, default_mode); elseif (all (c > 0)) - i = __sort_rows_idx__ (m(:,c), default_mode); + i = __sort_rows_idx__ (A(:,c), default_mode); elseif (all (c < 0)) - i = __sort_rows_idx__ (m(:,-c), other_mode); + i = __sort_rows_idx__ (A(:,-c), other_mode); else ## Otherwise, fall back to the old algorithm. - i = sort_rows_idx_generic (default_mode, other_mode, m, c); + i = sort_rows_idx_generic (default_mode, other_mode, A, c); endif ## Only bother to compute s if needed. if (isargout (1)) - s = m(i,:); + s = A(i,:); endif endfunction @@ -91,13 +91,13 @@ endfunction -%!shared m, c, x, idx, sx, sidx +%!test %! m = [1, 1; 1, 2; 3, 6; 2, 7]; %! c = [1, -2]; %! [x, idx] = sortrows (m, c); %! [sx, sidx] = sortrows (sparse (m), c); -%!assert (x, [1, 2; 1, 1; 2, 7; 3, 6]); -%!assert (idx, [2; 1; 4; 3]); -%!assert (issparse (sx)); -%!assert (x, full (sx)); -%!assert (idx, sidx); +%! assert (x, [1, 2; 1, 1; 2, 7; 3, 6]); +%! assert (idx, [2; 1; 4; 3]); +%! assert (issparse (sx)); +%! assert (x, full (sx)); +%! assert (idx, sidx); diff --git a/scripts/general/strerror.m b/scripts/general/strerror.m --- a/scripts/general/strerror.m +++ b/scripts/general/strerror.m @@ -27,7 +27,7 @@ ## Author: jwe -function msg = strerror (name, err) +function msg = strerror (name, num) if (nargin != 2) print_usage (); @@ -37,22 +37,22 @@ error ("strerror: first argument must be a string"); endif - if (! isscalar (err)) + if (! isscalar (num)) error ("strerror: second argument must be a scalar"); endif if (strcmp (name, "fsolve")) - if (err == -2) + if (num == -2) msg = "input error\n"; - elseif (err == -1) + elseif (num == -1) msg = "error encountered in user-supplied function\n"; - elseif (err == 1) + elseif (num == 1) msg = "solution converged to requested tolerance\n"; - elseif (err == 4) + elseif (num == 3) + msg = "iteration is not making good progress\n"; + elseif (num == 4) msg = "iteration limit exceeded\n"; - elseif (err == 3) - msg = "iteration is not making good progress\n"; else error ("strerror: unrecognized error code for fsolve"); endif diff --git a/scripts/general/structfun.m b/scripts/general/structfun.m --- a/scripts/general/structfun.m +++ b/scripts/general/structfun.m @@ -18,13 +18,13 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} structfun (@var{func}, @var{s}) +## @deftypefn {Function File} {} structfun (@var{func}, @var{S}) ## @deftypefnx {Function File} {[@var{a}, @dots{}] =} structfun (@dots{}) ## @deftypefnx {Function File} {} structfun (@dots{}, "ErrorHandler", @var{errfunc}) ## @deftypefnx {Function File} {} structfun (@dots{}, "UniformOutput", @var{val}) ## ## Evaluate the function named @var{name} on the fields of the structure -## @var{s}. The fields of @var{s} are passed to the function @var{func} +## @var{S}. The fields of @var{S} are passed to the function @var{func} ## individually. ## ## @code{structfun} accepts an arbitrary function @var{func} in the form of @@ -73,7 +73,7 @@ ## @seealso{cellfun, arrayfun, spfun} ## @end deftypefn -function varargout = structfun (fun, s, varargin); +function varargout = structfun (func, S, varargin); if (nargin < 2) print_usage (); @@ -103,10 +103,10 @@ endif varargout = cell (max ([nargout, 1]), 1); - [varargout{:}] = cellfun (fun, struct2cell (s), varargin{:}); + [varargout{:}] = cellfun (func, struct2cell (S), varargin{:}); if (! uniform_output) - varargout = cellfun (@cell2struct, varargout, {fieldnames(s)}, {1}, uo_str, false); + varargout = cellfun (@cell2struct, varargout, {fieldnames(S)}, {1}, uo_str, false); endif endfunction diff --git a/scripts/geometry/delaunayn.m b/scripts/geometry/delaunayn.m --- a/scripts/geometry/delaunayn.m +++ b/scripts/geometry/delaunayn.m @@ -17,14 +17,14 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{T} =} delaunayn (@var{P}) -## @deftypefnx {Function File} {@var{T} =} delaunayn (@var{P}, @var{opt}) +## @deftypefn {Function File} {@var{t} =} delaunayn (@var{p}) +## @deftypefnx {Function File} {@var{t} =} delaunayn (@var{p}, @var{opt}) ## Form the Delaunay triangulation for a set of points. ## The Delaunay triangulation is a tessellation of the convex hull of the ## points such that no n-sphere defined by the n-triangles contains ## any other points from the set. -## The input matrix @var{P} of size @code{[n, dim]} contains @var{n} -## points in a space of dimension dim. The return matrix @var{T} has the +## The input matrix @var{p} of size @code{[n, dim]} contains @math{n} +## points in a space of dimension dim. The return matrix @var{t} has the ## size @code{[m, dim+1]}. It contains for each row a set of indices to ## the points, which describes a simplex of dimension dim. For example, ## a 2d simplex is a triangle and 3d simplex is a tetrahedron. @@ -48,21 +48,21 @@ ## ## @end deftypefn -function t = delaunayn (x, varargin) +function t = delaunayn (p, varargin) if (nargin < 1) print_usage (); endif - t = __delaunayn__ (x, varargin{:}); + t = __delaunayn__ (p, varargin{:}); - if (isa (x, "single")) + if (isa (p, "single")) myeps = eps ("single"); else myeps = eps; endif ## Try to remove the zero volume simplices. The volume of the i-th simplex is - ## given by abs(det(x(t(i,1:end-1),:)-x(t(i,2:end),:)))/prod(1:n) + ## given by abs(det(p(t(i,1:end-1),:)-p(t(i,2:end),:)))/prod(1:n) ## (reference http://en.wikipedia.org/wiki/Simplex). Any simplex with a ## relative volume less than some arbitrary criteria is rejected. The ## criteria we use is the volume of the simplex corresponding to an @@ -73,7 +73,7 @@ idx = []; [nt, n] = size (t); for i = 1:nt - X = x(t(i,1:end-1),:) - x(t(i,2:end),:); + X = p(t(i,1:end-1),:) - p(t(i,2:end),:); if (abs (det (X)) / sqrt (sum (X .^ 2, 2)) < 1e3 * myeps) idx = [idx, i]; endif diff --git a/scripts/geometry/dsearch.m b/scripts/geometry/dsearch.m --- a/scripts/geometry/dsearch.m +++ b/scripts/geometry/dsearch.m @@ -21,11 +21,11 @@ ## @deftypefnx {Function File} {@var{idx} =} dsearch (@var{x}, @var{y}, @var{tri}, @var{xi}, @var{yi}, @var{s}) ## Returns the index @var{idx} or the closest point in @code{@var{x}, @var{y}} ## to the elements @code{[@var{xi}(:), @var{yi}(:)]}. The variable @var{s} is -## accepted but ignored for compatibility. +## accepted for compatibility but is ignored. ## @seealso{dsearchn, tsearch} ## @end deftypefn -function idx = dsearch (x, y, t, xi, yi, s) +function idx = dsearch (x, y, tri, xi, yi, s) if (nargin < 5 || nargin > 6) print_usage (); endif diff --git a/scripts/geometry/dsearchn.m b/scripts/geometry/dsearchn.m --- a/scripts/geometry/dsearchn.m +++ b/scripts/geometry/dsearchn.m @@ -29,17 +29,17 @@ ## @seealso{dsearch, tsearch} ## @end deftypefn -function [idx, d] = dsearchn (x, t, xi, outval) +function [idx, d] = dsearchn (x, tri, xi, outval) if (nargin < 2 || nargin > 4) print_usage (); endif if (nargin == 2) - [idx, d] = __dsearchn__ (x, t); + [idx, d] = __dsearchn__ (x, tri); else [idx, d] = __dsearchn__ (x, xi); if (nargin == 4) - idx2 = isnan (tsearchn (x, t, xi)); + idx2 = isnan (tsearchn (x, tri, xi)); idx(idx2) = outval; d(idx2) = outval; endif diff --git a/scripts/geometry/inpolygon.m b/scripts/geometry/inpolygon.m --- a/scripts/geometry/inpolygon.m +++ b/scripts/geometry/inpolygon.m @@ -18,9 +18,9 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{in}, @var{on}] =} inpolygon (@var{x}, @var{y}, @var{xv}, @var{xy}) +## @deftypefn {Function File} {[@var{in}, @var{on}] =} inpolygon (@var{x}, @var{y}, @var{xv}, @var{yv}) ## -## For a polygon defined by @code{(@var{xv}, @var{yv})} points, determine +## For a polygon defined by vertex points @code{(@var{xv}, @var{yv})}, determine ## if the points @code{(@var{x}, @var{y})} are inside or outside the polygon. ## The variables @var{x}, @var{y}, must have the same dimension. The optional ## output @var{on} gives the points that are on the polygon. @@ -37,14 +37,14 @@ ## http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/ and is ## credited to Randolph Franklin. -function [IN, ON] = inpolygon (X, Y, xv, yv) +function [in, on] = inpolygon (x, y, xv, yv) if (nargin != 4) print_usage (); endif - if (! (isreal (X) && isreal (Y) && ismatrix (Y) && ismatrix (Y) - && size_equal (X, Y))) + if (! (isreal (x) && isreal (y) && ismatrix (y) && ismatrix (y) + && size_equal (x, y))) error ("inpolygon: first two arguments must be real matrices of same size"); elseif (! (isreal (xv) && isreal (yv) && isvector (xv) && isvector (yv) && size_equal (xv, yv))) @@ -54,30 +54,30 @@ npol = length (xv); do_boundary = (nargout >= 2); - IN = zeros (size(X), "logical"); + in = zeros (size(x), "logical"); if (do_boundary) - ON = zeros (size(X), "logical"); + on = zeros (size(x), "logical"); endif j = npol; for i = 1 : npol delta_xv = xv(j) - xv(i); delta_yv = yv(j) - yv(i); - ## distance = [distance from (X,Y) to edge] * length(edge) - distance = delta_xv .* (Y - yv(i)) - (X - xv(i)) .* delta_yv; + ## distance = [distance from (x,y) to edge] * length(edge) + distance = delta_xv .* (y - yv(i)) - (x - xv(i)) .* delta_yv; ## - ## is Y between the y-values of edge i,j - ## AND (X,Y) on the left of the edge ? - idx1 = (((yv(i) <= Y & Y < yv(j)) | (yv(j) <= Y & Y < yv(i))) + ## is y between the y-values of edge i,j + ## AND (x,y) on the left of the edge ? + idx1 = (((yv(i) <= y & y < yv(j)) | (yv(j) <= y & y < yv(i))) & 0 < distance.*delta_yv); - IN (idx1) = !IN (idx1); + in (idx1) = !in (idx1); - ## Check if (X,Y) are actually ON the boundary of the polygon. + ## Check if (x,y) are actually on the boundary of the polygon. if (do_boundary) - idx2 = (((yv(i) <= Y & Y <= yv(j)) | (yv(j) <= Y & Y <= yv(i))) - & ((xv(i) <= X & X <= xv(j)) | (xv(j) <= X & X <= xv(i))) + idx2 = (((yv(i) <= y & y <= yv(j)) | (yv(j) <= y & y <= yv(i))) + & ((xv(i) <= x & x <= xv(j)) | (xv(j) <= x & x <= xv(i))) & (0 == distance | !delta_xv)); - ON (idx2) = true; + on (idx2) = true; endif j = i; endfor @@ -94,14 +94,14 @@ %! xa=[0:0.1:2.3]; %! ya=[0:0.1:1.4]; %! [x,y]=meshgrid(xa,ya); -%! [IN,ON]=inpolygon(x,y,xv,yv); +%! [in,on]=inpolygon(x,y,xv,yv); %! -%! inside=IN & !ON; +%! inside=in & !on; %! plot(xv,yv) %! hold on %! plot(x(inside),y(inside),"@g") -%! plot(x(~IN),y(~IN),"@m") -%! plot(x(ON),y(ON),"@b") +%! plot(x(~in),y(~in),"@m") +%! plot(x(on),y(on),"@b") %! hold off %! disp("Green points are inside polygon, magenta are outside,"); %! disp("and blue are on boundary."); @@ -118,14 +118,14 @@ %! xa=[0:0.1:2.3]; %! ya=[0:0.1:1.4]; %! [x,y]=meshgrid(xa,ya); -%! [IN,ON]=inpolygon(x,y,xv,yv); +%! [in,on]=inpolygon(x,y,xv,yv); %! -%! inside=IN & ~ ON; +%! inside=in & ~ on; %! plot(xv,yv) %! hold on %! plot(x(inside),y(inside),"@g") -%! plot(x(~IN),y(~IN),"@m") -%! plot(x(ON),y(ON),"@b") +%! plot(x(~in),y(~in),"@m") +%! plot(x(on),y(on),"@b") %! hold off %! disp("Green points are inside polygon, magenta are outside,"); %! disp("and blue are on boundary."); diff --git a/scripts/geometry/voronoin.m b/scripts/geometry/voronoin.m --- a/scripts/geometry/voronoin.m +++ b/scripts/geometry/voronoin.m @@ -19,7 +19,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{C}, @var{F}] =} voronoin (@var{pts}) ## @deftypefnx {Function File} {[@var{C}, @var{F}] =} voronoin (@var{pts}, @var{options}) -## computes n- dimensional Voronoi facets. The input matrix @var{pts} +## Compute N-dimensional Voronoi facets. The input matrix @var{pts} ## of size [n, dim] contains n points of dimension dim. ## @var{C} contains the points of the Voronoi facets. The list @var{F} ## contains for each facet the indices of the Voronoi points. @@ -37,7 +37,7 @@ ## Added optional second argument to pass options to the underlying ## qhull command -function [C, F] = voronoin (pts, opt) +function [C, F] = voronoin (pts, options) if (nargin != 1 && nargin != 2) print_usage (); @@ -47,8 +47,8 @@ if (np > dims) if (nargin == 1) [C, F, infi] = __voronoi__ (pts); - elseif ischar(opt) - [C, F, infi] = __voronoi__ (pts, opt); + elseif (ischar (options)) + [C, F, infi] = __voronoi__ (pts, options); else error ("voronoin: second argument must be a string"); endif diff --git a/scripts/help/lookfor.m b/scripts/help/lookfor.m --- a/scripts/help/lookfor.m +++ b/scripts/help/lookfor.m @@ -41,13 +41,13 @@ ## @seealso{help, doc, which} ## @end deftypefn -function [out_fun, out_help_text] = lookfor (str, extra) +function [out_fun, out_help_text] = lookfor (str, arg2) if (strcmpi (str, "-all")) ## The difference between using '-all' and not, is which part of the caches ## we search. The cache is organised such that its first column contains ## the function name, its second column contains the full help text, and its ## third column contains the first sentence of the help text. - str = extra; + str = arg2; search_type = 2; # when using caches, search its second column else search_type = 3; # when using caches, search its third column diff --git a/scripts/image/brighten.m b/scripts/image/brighten.m --- a/scripts/image/brighten.m +++ b/scripts/image/brighten.m @@ -34,17 +34,19 @@ ## @seealso{colormap} ## @end deftypefn -function Rmap = brighten (m, beta) +function rmap = brighten (arg1, beta) h = -1; if (nargin == 1) - beta = m; + beta = arg1; m = colormap; h = gcf (); elseif (nargin == 2) - if (ishandle (m)) - h = m; + if (ishandle (arg1)) + h = arg1; m = get (h, "colormap"); - elseif (! ismatrix (m) || size (m, 2) != 3) + elseif (ismatrix (arg1) && columns (arg1) == 3) + m = arg1; + else error ("brighten: first argument must be an Nx3 matrix or a handle"); endif else @@ -68,7 +70,7 @@ colormap (m .^ gamma); endif else - Rmap = m .^ gamma; + rmap = m .^ gamma; endif endfunction diff --git a/scripts/image/ind2gray.m b/scripts/image/ind2gray.m --- a/scripts/image/ind2gray.m +++ b/scripts/image/ind2gray.m @@ -29,7 +29,7 @@ ## Created: July 1994 ## Adapted-By: jwe -function Y = ind2gray (X, map) +function y = ind2gray (x, map) if (nargin < 1 || nargin > 2) print_usage (); @@ -37,14 +37,14 @@ map = colormap (); endif - [rows, cols] = size (X); + [rows, cols] = size (x); ## Convert colormap to intensity values (the first column of the ## result of the call to rgb2ntsc) and then replace indices in ## the input matrix with indexed values in the output matrix (indexed ## values are the result of indexing the intensity values by the - ## elements of X(:)). + ## elements of x(:)). - Y = reshape (((rgb2ntsc (map))(:,1))(X(:)), rows, cols); + y = reshape (((rgb2ntsc (map))(:,1))(x(:)), rows, cols); endfunction diff --git a/scripts/image/ind2rgb.m b/scripts/image/ind2rgb.m --- a/scripts/image/ind2rgb.m +++ b/scripts/image/ind2rgb.m @@ -19,7 +19,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{rgb} =} ind2rgb (@var{x}, @var{map}) -## @deftypefnx {Function File} {[@var{r}, @var{g}, @var{b}] =} ind2rgb (@var{x}, @var{map}) +## @deftypefnx {Function File} {[@var{R}, @var{R}, @var{R}] =} ind2rgb (@var{x}, @var{map}) ## Convert an indexed image to red, green, and blue color components. ## If the colormap doesn't contain enough colors, pad it with the ## last color in the map. @@ -31,7 +31,7 @@ ## Created: July 1994 ## Adapted-By: jwe -function [R, G, B] = ind2rgb (X, map) +function [R, G, B] = ind2rgb (x, map) ## Do we have the right number of inputs? if (nargin < 1 || nargin > 2) @@ -41,7 +41,7 @@ endif ## Check if X is an indexed image. - if (ndims (X) != 2 || any (X(:) != round (X(:))) || min (X(:)) < 1) + if (ndims (x) != 2 || any (x(:) != round (x(:))) || min (x(:)) < 1) error ("ind2rgb: first input argument must be an indexed image"); endif @@ -51,7 +51,7 @@ endif ## Do we have enough colors in the color map? - maxidx = max (X(:)); + maxidx = max (x(:)); rm = rows (map); if (rm < maxidx) ## Pad with the last color in the map. @@ -60,10 +60,10 @@ endif ## Compute result - [hi, wi] = size (X); - R = reshape (map (X(:), 1), hi, wi); - G = reshape (map (X(:), 2), hi, wi); - B = reshape (map (X(:), 3), hi, wi); + [hi, wi] = size (x); + R = reshape (map (x(:), 1), hi, wi); + G = reshape (map (x(:), 2), hi, wi); + B = reshape (map (x(:), 3), hi, wi); ## Use 3D array if only one output is requested. if (nargout <= 1) diff --git a/scripts/image/rgb2hsv.m b/scripts/image/rgb2hsv.m --- a/scripts/image/rgb2hsv.m +++ b/scripts/image/rgb2hsv.m @@ -18,7 +18,7 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{hsv_map} =} rgb2hsv (@var{rgb_map}) +## @deftypefn {Function File} {@var{hsv_map} =} rgb2hsv (@var{rgb}) ## Transform a colormap or image from the RGB space to the HSV space. ## ## A color in the RGB space consists of the red, green and blue intensities. @@ -33,7 +33,7 @@ ## Author: Kai Habel ## Adapted-by: jwe -function hsval = rgb2hsv (rgb) +function hsv_map = rgb2hsv (rgb) if (nargin != 1) print_usage (); @@ -56,7 +56,7 @@ endif if (! ismatrix (rgb) || columns (rgb) != 3) - error ("rgb2hsv: argument must be a matrix of size n x 3"); + error ("rgb2hsv: RGB_MAP must be a matrix of size n x 3"); endif ## get the max and min @@ -93,11 +93,11 @@ s(! notgray) = 0; s(notgray) = 1 - s(notgray) ./ v(notgray); - hsval = [h, s, v]; + hsv_map = [h, s, v]; ## If input was an image, convert it back into one. if (is_image) - hsval = reshape (hsval, Sz); + hsv_map = reshape (hsv_map, Sz); endif endfunction diff --git a/scripts/image/rgb2ind.m b/scripts/image/rgb2ind.m --- a/scripts/image/rgb2ind.m +++ b/scripts/image/rgb2ind.m @@ -19,7 +19,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{rgb}) -## @deftypefnx {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{r}, @var{g}, @var{b}) +## @deftypefnx {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{R}, @var{G}, @var{B}) ## Convert an RGB image to an Octave indexed image. ## @seealso{ind2rgb, rgb2ntsc} ## @end deftypefn @@ -30,7 +30,7 @@ ## Created: July 1994 ## Adapted-By: jwe -function [X, map] = rgb2ind (R, G, B) +function [x, map] = rgb2ind (R, G, B) if (nargin != 1 && nargin != 3) print_usage (); @@ -53,7 +53,7 @@ [hi, wi] = size (R); - X = zeros (hi, wi); + x = zeros (hi, wi); map = zeros (hi*wi, 3); @@ -61,6 +61,6 @@ map(:,2) = G(:); map(:,3) = B(:); - X(:) = 1:(hi*wi); + x(:) = 1:(hi*wi); endfunction diff --git a/scripts/image/saveimage.m b/scripts/image/saveimage.m --- a/scripts/image/saveimage.m +++ b/scripts/image/saveimage.m @@ -18,9 +18,10 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} saveimage (@var{file}, @var{x}, @var{fmt}, @var{map}) -## Save the matrix @var{x} to @var{file} in image format @var{fmt}. Valid -## values for @var{fmt} are +## @deftypefn {Function File} {} saveimage (@var{fname}, @var{img}, @var{fmt}) +## @deftypefnx {Function File} {} saveimage (@var{fname}, @var{img}, @var{fmt}, @var{map}) +## Save the matrix @var{img} to file @var{fname} in image format @var{fmt}. +## Valid values for @var{fmt} are ## ## @table @code ## @item "img" @@ -74,7 +75,7 @@ ## documentation. This software is provided "as is" without express or ## implied warranty. -function saveimage (filename, img, img_form, map) +function saveimage (fname, img, fmt, map) if (nargin < 2 || nargin > 4) print_usage (); @@ -95,12 +96,12 @@ endif if (nargin < 3) - img_form = "img"; - elseif (! ischar (img_form)) + fmt = "img"; + elseif (! ischar (fmt)) error ("saveimage: image format specification must be a string"); - elseif (! (strcmp (img_form, "img") - || strcmp (img_form, "ppm") - || strcmp (img_form, "ps"))) + elseif (! (strcmp (fmt, "img") + || strcmp (fmt, "ppm") + || strcmp (fmt, "ps"))) error ("saveimage: unsupported image format specification"); endif @@ -108,14 +109,14 @@ warning ("image variable is not a matrix"); endif - if (! ischar (filename)) - error ("saveimage: file name must be a string"); + if (! ischar (fname)) + error ("saveimage: fname name must be a string"); endif ## If we just want Octave image format, save and return. - if (strcmp (img_form, "img")) - save ("-text", filename, "map", "img"); + if (strcmp (fmt, "img")) + save ("-text", fname, "map", "img"); return; endif @@ -147,7 +148,7 @@ img (img > map_nr) = map_nr; img (img <= 0) = 1; - if (strcmp (img_form, "ppm")) + if (strcmp (fmt, "ppm")) ## Would be nice to make this consistent with the line used by the ## load/save functions, but we need a good way to get username and @@ -183,7 +184,7 @@ tmp(i,:) = sum (bwimg(8*(i-1)+1:8*i,:) .* b); endfor - fid = fopen (filename, "wb"); + fid = fopen (fname, "wb"); fprintf (fid, "P4\n%s\n%d %d\n", tagline, img_nr, img_nc); fwrite (fid, tmp, "uchar"); fprintf (fid, "\n"); @@ -191,7 +192,7 @@ elseif (grey) - fid = fopen (filename, "wb"); + fid = fopen (fname, "wb"); fprintf (fid, "P5\n%s\n%d %d\n255\n", tagline, img_nr, img_nc); fwrite (fid, map(img), "uchar"); fprintf (fid, "\n"); @@ -213,7 +214,7 @@ tmap = map(map_idx); tmp(img_idx--) = tmap(img); - fid = fopen (filename, "wb"); + fid = fopen (fname, "wb"); fprintf (fid, "P6\n%s\n%d %d\n255\n", tagline, img_nr, img_nc); fwrite (fid, tmp, "uchar"); fprintf (fid, "\n"); @@ -221,7 +222,7 @@ endif - elseif (strcmp (img_form, "ps") == 1) + elseif (strcmp (fmt, "ps") == 1) if (! grey) error ("saveimage: must have a greyscale color map for conversion to PostScript"); @@ -263,11 +264,11 @@ urx = llx + fix (scols + 0.5); ury = lly + fix (srows + 0.5); - fid = fopen (filename, "wb"); + fid = fopen (fname, "wb"); fprintf (fid, "%%!PS-Adobe-2.0 EPSF-2.0\n"); fprintf (fid, "%%%%Creator: Octave %s (saveimage.m)\n", OCTAVE_VERSION); - fprintf (fid, "%%%%Title: %s\n", filename); + fprintf (fid, "%%%%Title: %s\n", fname); fprintf (fid, "%%%%Pages: 1\n"); fprintf (fid, "%%%%BoundingBox: %d %d %d %d\n", fix (llx), fix (lly), fix (urx), fix (ury)); diff --git a/scripts/io/csvread.m b/scripts/io/csvread.m --- a/scripts/io/csvread.m +++ b/scripts/io/csvread.m @@ -30,6 +30,6 @@ ## @seealso{csvwrite, dlmread, dlmwrite} ## @end deftypefn -function x = csvread (f, varargin) - x = dlmread (f, ",", varargin{:}); +function x = csvread (filename, varargin) + x = dlmread (filename, ",", varargin{:}); endfunction diff --git a/scripts/io/csvwrite.m b/scripts/io/csvwrite.m --- a/scripts/io/csvwrite.m +++ b/scripts/io/csvwrite.m @@ -31,6 +31,6 @@ ## @seealso{csvread, dlmwrite, dlmread} ## @end deftypefn -function csvwrite (f, m, varargin) - dlmwrite (f, m, ",", varargin{:}); +function csvwrite (filename, x, varargin) + dlmwrite (filename, x, ",", varargin{:}); endfunction diff --git a/scripts/io/strread.m b/scripts/io/strread.m --- a/scripts/io/strread.m +++ b/scripts/io/strread.m @@ -99,13 +99,13 @@ ## @seealso{textread, load, dlmread, fscanf} ## @end deftypefn -function varargout = strread (str, formatstr = "%f", varargin) +function varargout = strread (str, format = "%f", varargin) ## Check input if (nargin < 1) print_usage (); endif - if (!ischar (str) || !ischar (formatstr)) + if (!ischar (str) || !ischar (format)) error ("strread: first and second input arguments must be strings"); endif @@ -150,10 +150,10 @@ endif ## Parse format string - idx = strfind (formatstr, "%")'; - specif = formatstr ([idx, idx+1]); + idx = strfind (format, "%")'; + specif = format ([idx, idx+1]); nspecif = length (idx); - idx_star = strfind (formatstr, "%*"); + idx_star = strfind (format, "%*"); nfields = length (idx) - length (idx_star); if (max (nargout, 1) != nfields) @@ -187,8 +187,8 @@ endif ## Determine the number of words per line - formatstr = strrep (formatstr, "%", " %"); - [~, ~, ~, fmt_words] = regexp (formatstr, "[^\\s]+"); + format = strrep (format, "%", " %"); + [~, ~, ~, fmt_words] = regexp (format, "[^\\s]+"); num_words_per_line = numel (fmt_words); for m = 1:numel(fmt_words) diff --git a/scripts/io/textread.m b/scripts/io/textread.m --- a/scripts/io/textread.m +++ b/scripts/io/textread.m @@ -36,13 +36,13 @@ ## @seealso{strread, load, dlmread, fscanf} ## @end deftypefn -function varargout = textread (filename, formatstr = "%f", varargin) +function varargout = textread (filename, format = "%f", varargin) ## Check input if (nargin < 1) print_usage (); endif - if (!ischar (filename) || !ischar (formatstr)) + if (!ischar (filename) || !ischar (format)) error ("textread: first and second input arguments must be strings"); endif @@ -63,5 +63,6 @@ fclose (fid); ## Call strread to make it do the real work - [varargout{1:max (nargout, 1)}] = strread (str, formatstr, varargin {:}); + [varargout{1:max (nargout, 1)}] = strread (str, format, varargin {:}); + endfunction diff --git a/scripts/io/textscan.m b/scripts/io/textscan.m --- a/scripts/io/textscan.m +++ b/scripts/io/textscan.m @@ -50,13 +50,13 @@ ## @seealso{dlmread, fscanf, load, strread, textread} ## @end deftypefn -function [c, p] = textscan (fid, formatstr, varargin) +function [c, p] = textscan (fid, format, varargin) ## Check input if (nargin < 1) print_usage (); - elseif (nargin == 1 || isempty (formatstr)) - formatstr = "%f"; + elseif (nargin == 1 || isempty (format)) + format = "%f"; endif if (nargin > 2 && isnumeric (varargin{1})) @@ -74,7 +74,7 @@ endif if (isa (fid, "double") && fid > 0 || ischar (fid)) - if (ischar (formatstr)) + if (ischar (format)) if (ischar (fid)) if (nargout == 2) error ("textscan: cannot provide postion information for character input") @@ -98,12 +98,12 @@ endif ## Determine the number of data fields - num_fields = numel (strfind (formatstr, "%")) - ... - numel (idx_star = strfind (formatstr, "%*")); + num_fields = numel (strfind (format, "%")) - ... + numel (idx_star = strfind (format, "%*")); ## Call strread to make it do the real work c = cell (1, num_fields); - [c{:}] = strread (str, formatstr, args{:}); + [c{:}] = strread (str, format, args{:}); if (ischar (fid) && isfinite (nlines)) c = cellfun (@(x) x(1:nlines), c, "uniformoutput", false); diff --git a/scripts/linear-algebra/rref.m b/scripts/linear-algebra/rref.m --- a/scripts/linear-algebra/rref.m +++ b/scripts/linear-algebra/rref.m @@ -17,10 +17,10 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{r}, @var{k}] =} rref (@var{a}, @var{tol}) +## @deftypefn {Function File} {[@var{r}, @var{k}] =} rref (@var{A}, @var{tol}) ## -## Returns the reduced row echelon form of @var{a}. @var{tol} defaults -## to @code{eps * max (size (@var{a})) * norm (@var{a}, inf)}. +## Returns the reduced row echelon form of @var{A}. @var{tol} defaults +## to @code{eps * max (size (@var{A})) * norm (@var{A}, inf)}. ## ## Called with two return arguments, @var{k} returns the vector of ## "bound variables", which are those columns on which elimination @@ -29,9 +29,9 @@ ## @end deftypefn ## Author: Paul Kienzle -## (based on a anonymous source from the public domain) +## (based on an anonymous source from the public domain) -function [A, k] = rref (A, tolerance) +function [A, k] = rref (A, tol) if (nargin < 1 || nargin > 2) print_usage (); @@ -45,9 +45,9 @@ if (nargin < 2) if (isa (A, "single")) - tolerance = eps ("single") * max (rows, cols) * norm (A, inf ("single")); + tol = eps ("single") * max (rows, cols) * norm (A, inf ("single")); else - tolerance = eps * max (rows, cols) * norm (A, inf); + tol = eps * max (rows, cols) * norm (A, inf); endif endif @@ -58,7 +58,7 @@ [m, pivot] = max (abs (A(r:rows,c))); pivot = r + pivot - 1; - if (m <= tolerance) + if (m <= tol) ## Skip column c, making sure the approximately zero terms are ## actually zero. A (r:rows, c) = zeros (rows-r+1, 1); diff --git a/scripts/linear-algebra/subspace.m b/scripts/linear-algebra/subspace.m --- a/scripts/linear-algebra/subspace.m +++ b/scripts/linear-algebra/subspace.m @@ -17,9 +17,9 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{angle} =} subspace (@var{a}, @var{B}) +## @deftypefn {Function File} {@var{angle} =} subspace (@var{A}, @var{B}) ## Determine the largest principal angle between two subspaces -## spanned by columns of matrices @var{a} and @var{b}. +## spanned by the columns of matrices @var{A} and @var{B}. ## @end deftypefn ## Author: Jaroslav Hajek @@ -32,25 +32,25 @@ ## ## other texts are also around... -function ang = subspace (a, b) +function ang = subspace (A, B) if (nargin != 2) print_usage (); - elseif (ndims (a) != 2 || ndims (b) != 2) + elseif (ndims (A) != 2 || ndims (B) != 2) error ("subspace: expecting A and B to be 2-dimensional arrays"); - elseif (rows (a) != rows (b)) - error ("subspace: column dimensions of a and b must match"); + elseif (rows (A) != rows (B)) + error ("subspace: column dimensions of A and B must match"); endif - a = orth (a); - b = orth (b); - c = a'*b; + A = orth (A); + B = orth (B); + c = A'*B; scos = min (svd (c)); if (scos^2 > 1/2) - if (columns (a) >= columns (b)) - c = b - a*c; + if (columns (A) >= columns (B)) + c = B - A*c; else - c = a - b*c'; + c = A - B*c'; endif ssin = max (svd (c)); ang = asin (min (ssin, 1)); diff --git a/scripts/linear-algebra/trace.m b/scripts/linear-algebra/trace.m --- a/scripts/linear-algebra/trace.m +++ b/scripts/linear-algebra/trace.m @@ -18,26 +18,26 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} trace (@var{a}) -## Compute the trace of @var{a}, @code{sum (diag (@var{a}))}. +## @deftypefn {Function File} {} trace (@var{A}) +## Compute the trace of @var{A}, @code{sum (diag (@var{A}))}. ## @end deftypefn ## Author: jwe -function y = trace (x) +function y = trace (A) if (nargin != 1) print_usage (); endif - if (ndims (x) > 2) + if (ndims (A) > 2) error ("trace: only valid on 2-D objects"); - elseif (isempty (x)) + elseif (isempty (A)) y = 0; - elseif (any (size (x) == 1)) - y = x(1); + elseif (any (size (A) == 1)) + y = A(1); else - y = sum (diag (x)); + y = sum (diag (A)); endif endfunction diff --git a/scripts/miscellaneous/bunzip2.m b/scripts/miscellaneous/bunzip2.m --- a/scripts/miscellaneous/bunzip2.m +++ b/scripts/miscellaneous/bunzip2.m @@ -25,21 +25,17 @@ ## Author: Bill Denney -function varargout = bunzip2 (files, outputdir) +function varargout = bunzip2 (bzfile, dir = ".") - if (! (nargin == 1 || nargin == 2)) + if (nargin != 1 && nargin != 2) print_usage (); endif - if (nargin == 1) - outputdir = "."; - endif - if (nargout > 0) varargout = cell (1, nargout); - [varargout{:}] = unpack (files, outputdir, mfilename ()); + [varargout{:}] = unpack (bzfile, dir, mfilename ()); else - unpack (files, outputdir, mfilename ()); + unpack (bzfile, dir, mfilename ()); endif endfunction diff --git a/scripts/miscellaneous/dir.m b/scripts/miscellaneous/dir.m --- a/scripts/miscellaneous/dir.m +++ b/scripts/miscellaneous/dir.m @@ -52,10 +52,10 @@ ## FIXME -- this is quite slow for large directories, so perhaps ## it should be converted to C++. -function retval = dir (file) +function retval = dir (directory) if (nargin == 0) - file = "."; + directory = "."; elseif (nargin > 1) print_usage (); endif @@ -64,15 +64,15 @@ info = struct (zeros (0, 1), {"name", "date", "bytes", "isdir", "datenum", "statinfo"}); - if (ischar (file)) - if (strcmp (file, "*")) - file = "."; + if (ischar (directory)) + if (strcmp (directory, "*")) + directory = "."; endif - if (strcmp (file, ".")) + if (strcmp (directory, ".")) flst = {"."}; nf = 1; else - flst = glob (file); + flst = glob (directory); nf = length (flst); endif @@ -136,7 +136,7 @@ ## Print the structure to the screen. printf ("%s", list_in_columns ({info.name})); else - warning ("dir: nonexistent file `%s'", file); + warning ("dir: nonexistent directory `%s'", directory); endif endfunction diff --git a/scripts/miscellaneous/dos.m b/scripts/miscellaneous/dos.m --- a/scripts/miscellaneous/dos.m +++ b/scripts/miscellaneous/dos.m @@ -30,12 +30,12 @@ ## Author: octave-forge ??? ## Adapted by: jwe -function [status, text] = dos (cmd, echo_arg) +function [status, text] = dos (command, echo_arg) if (nargin < 1 || nargin > 2) print_usage (); elseif (! isunix ()) - [status, text] = system (cmd); + [status, text] = system (command); if (nargin > 1 || nargout == 0) printf ("%s\n", text); endif diff --git a/scripts/miscellaneous/gunzip.m b/scripts/miscellaneous/gunzip.m --- a/scripts/miscellaneous/gunzip.m +++ b/scripts/miscellaneous/gunzip.m @@ -20,28 +20,24 @@ ## @deftypefn {Function File} {} gunzip (@var{gzfile}, @var{dir}) ## Unpack the gzip archive @var{gzfile} to the directory @var{dir}. If ## @var{dir} is not specified, it defaults to the current directory. If -## the @var{gzfile} is a directory, all files in the directory will be +## the @var{gzfile} is a directory, all gzfile in the directory will be ## recursively gunzipped. ## @seealso{unpack, bunzip2, tar, untar, gzip, gunzip, zip, unzip} ## @end deftypefn ## Author: Bill Denney -function varargout = gunzip (files, outputdir) +function varargout = gunzip (gzfile, dir = ".") - if (! (nargin == 1 || nargin == 2)) + if (nargin != 1 && nargin != 2) print_usage (); endif - if (nargin == 1) - outputdir = "."; - endif - if (nargout > 0) varargout = cell (1, nargout); - [varargout{:}] = unpack (files, outputdir, mfilename ()); + [varargout{:}] = unpack (gzfile, dir, mfilename ()); else - unpack (files, outputdir, mfilename ()); + unpack (gzfile, dir, mfilename ()); endif endfunction diff --git a/scripts/miscellaneous/menu.m b/scripts/miscellaneous/menu.m --- a/scripts/miscellaneous/menu.m +++ b/scripts/miscellaneous/menu.m @@ -30,7 +30,7 @@ ## Author: jwe -function num = menu (t, varargin) +function num = menu (title, varargin) if (nargin < 2) print_usage (); @@ -49,8 +49,8 @@ page_screen_output (0); - if (! isempty (t)) - disp (t); + if (! isempty (title)) + disp (title); printf ("\n"); endif diff --git a/scripts/miscellaneous/perl.m b/scripts/miscellaneous/perl.m --- a/scripts/miscellaneous/perl.m +++ b/scripts/miscellaneous/perl.m @@ -26,16 +26,16 @@ ## @seealso{system} ## @end deftypefn -function [output, status] = perl (script = "-e ''", varargin) +function [output, status] = perl (scriptfile = "-e ''", varargin) ## VARARGIN is intialized to {}(1x0) if no additional arguments are ## supplied, so there is no need to check for it, or provide an ## initial value in the argument list of the function definition. - if (ischar (script) + if (ischar (scriptfile) && ((nargin != 1 && iscellstr (varargin)) - || (nargin == 1 && ! isempty (script)))) - [status, output] = system (cstrcat ("perl ", script, + || (nargin == 1 && ! isempty (scriptfile)))) + [status, output] = system (cstrcat ("perl ", scriptfile, sprintf (" %s", varargin{:}))); else error ("perl: invalid arguments"); diff --git a/scripts/miscellaneous/run.m b/scripts/miscellaneous/run.m --- a/scripts/miscellaneous/run.m +++ b/scripts/miscellaneous/run.m @@ -17,22 +17,22 @@ ## . ## -*- texinfo -*- -## @deftypefn {Command} {} run @var{f} -## @deftypefnx {Function File} {} run (@var{f}) +## @deftypefn {Command} {} run @var{script} +## @deftypefnx {Function File} {} run (@var{script}) ## Run scripts in the current workspace that are not necessarily on the -## path. If @var{f} is the script to run, including its path, then @code{run} -## changes the directory to the directory where @var{f} is found. @code{run} +## path. If @var{script} is the script to run, including its path, then @code{run} +## changes the directory to the directory where @var{script} is found. @code{run} ## then executes the script, and returns to the original directory. ## @seealso{system} ## @end deftypefn -function run (s) +function run (script) if (nargin != 1) print_usage (); endif - [d, f, ext] = fileparts (s); + [d, f, ext] = fileparts (script); if (! isempty (d)) if (exist (d, "dir")) wd = pwd (); @@ -50,11 +50,11 @@ error ("run: the path %s doesn't exist", d); endif else - if (exist (s, "file")) - evalin ("caller", sprintf ("source (\"%s\");", s), + if (exist (script, "file")) + evalin ("caller", sprintf ("source (\"%s\");", script), "rethrow (lasterror ())"); else - error ("run: %s not found", s); + error ("run: %s not found", script); endif endif endfunction diff --git a/scripts/miscellaneous/unix.m b/scripts/miscellaneous/unix.m --- a/scripts/miscellaneous/unix.m +++ b/scripts/miscellaneous/unix.m @@ -30,12 +30,12 @@ ## Author: octave-forge ??? ## Adapted by: jwe -function [status, text] = unix (cmd, echo_arg) +function [status, text] = unix (command, echo_arg) if (nargin < 1 || nargin > 2) print_usage (); elseif (isunix ()) - [status, text] = system (cmd); + [status, text] = system (command); if (nargin > 1 || nargout == 0) printf ("%s\n", text); endif diff --git a/scripts/miscellaneous/unpack.m b/scripts/miscellaneous/unpack.m --- a/scripts/miscellaneous/unpack.m +++ b/scripts/miscellaneous/unpack.m @@ -17,7 +17,8 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{files} =} unpack (@var{file}, @var{dir}) +## @deftypefn {Function File} {@var{files} =} unpack (@var{file}) +## @deftypefnx {Function File} {@var{files} =} unpack (@var{file}, @var{dir}) ## @deftypefnx {Function File} {@var{files} =} unpack (@var{file}, @var{dir}, @var{filetype}) ## Unpack the archive @var{file} based on its extension to the directory ## @var{dir}. If @var{file} is a cellstr, then all files will be @@ -32,19 +33,12 @@ ## Author: Bill Denney -function filelist = unpack (file, directory, filetype) +function filelist = unpack (file, dir = ".", filetype = "") if (nargin < 1 || nargin > 3) print_usage (); endif - if (nargin < 2) - directory = "."; - endif - if (nargin < 3) - filetype = ""; - endif - if (ischar (file)) if (isdir (file)) if (isempty (filetype)) @@ -64,13 +58,13 @@ endif endif - ## If the file is a url, download it and then work with that + ## If the file is a URL, download it and then work with that ## file. if (! isempty (strfind (file, "://"))) - ## FIXME -- the above is not a perfect test for a url + ## FIXME -- the above is not a perfect test for a URL urlfile = file; ## FIXME -- should we name the file that we download with the - ## same file name as the url requests? + ## same file name as the URL requests? tmpfile = cstrcat (tmpnam (), ext); [file, success, msg] = urlwrite (urlfile, tmpfile); if (! success) @@ -81,7 +75,7 @@ endif ## canonicalize_file_name returns empty if the file isn't found, so - ## use that to check for existence + ## use that to check for existence. cfile = canonicalize_file_name (file); if (isempty (cfile)) @@ -93,7 +87,7 @@ elseif (iscellstr (file)) files = {}; for i = 1:numel (file) - tmpfiles = unpack (file{i}, directory); + tmpfiles = unpack (file{i}, dir); files = {files{:} tmpfiles{:}}; endfor @@ -152,7 +146,7 @@ if (isfield (commandlist, nodotext)) [commandv, commandq, parser, move] = deal (commandlist.(nodotext){:}); cstartdir = canonicalize_file_name (origdir); - cenddir = canonicalize_file_name (directory); + cenddir = canonicalize_file_name (dir); needmove = move && ! strcmp (cstartdir, cenddir); if (nargout > 0 || needmove) command = commandv; @@ -166,18 +160,18 @@ endif ## Create the directory if necessary. - s = stat (directory); + s = stat (dir); if (isempty (s)) - [status, msg] = mkdir (directory); + [status, msg] = mkdir (dir); if (! status) - error ("unpack: mkdir failed to create %s: %s", directory, msg); + error ("unpack: mkdir failed to create %s: %s", dir, msg); endif elseif (! S_ISDIR (s.mode)) - error ("unpack: %s: not a directory", directory); + error ("unpack: %s: not a directory", dir); endif unwind_protect - cd (directory); + cd (dir); [status, output] = system (sprintf (cstrcat (command, " 2>&1"), file)); unwind_protect_cleanup cd (origdir); @@ -198,10 +192,10 @@ ## Move files if necessary if (needmove) - [st, msg, msgid] = movefile (files, directory); + [st, msg, msgid] = movefile (files, dir); if (! st) error ("unpack: unable to move files to \"%s\": %s", - directory, msg); + dir, msg); endif ## Fix the names for the files since they were moved. diff --git a/scripts/miscellaneous/untar.m b/scripts/miscellaneous/untar.m --- a/scripts/miscellaneous/untar.m +++ b/scripts/miscellaneous/untar.m @@ -26,21 +26,17 @@ ## Author: Søren Hauberg ## Adapted-By: jwe, Bill Denney -function varargout = untar (files, outputdir) +function varargout = untar (tarfile, dir = ".") - if (! (nargin == 1 || nargin == 2)) + if (nargin != 1 && nargin != 2) print_usage (); endif - if (nargin == 1) - outputdir = "."; - endif - if (nargout > 0) varargout = cell (1, nargout); - [varargout{:}] = unpack (files, outputdir, mfilename ()); + [varargout{:}] = unpack (tarfile, dir, mfilename ()); else - unpack (files, outputdir, mfilename ()); + unpack (tarfile, dir, mfilename ()); endif endfunction diff --git a/scripts/miscellaneous/unzip.m b/scripts/miscellaneous/unzip.m --- a/scripts/miscellaneous/unzip.m +++ b/scripts/miscellaneous/unzip.m @@ -17,7 +17,8 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} unzip (@var{zipfile}, @var{dir}) +## @deftypefn {Function File} {} unzip (@var{zipfile}) +## @deftypefnx {Function File} {} unzip (@var{zipfile}, @var{dir}) ## Unpack the ZIP archive @var{zipfile} to the directory @var{dir}. ## If @var{dir} is not specified, it defaults to the current directory. ## @seealso{unpack, bunzip2, tar, untar, gzip, gunzip, zip} @@ -26,21 +27,17 @@ ## Author: Søren Hauberg ## Adapted-By: jwe, Bill Denney -function varargout = unzip (files, outputdir) +function varargout = unzip (zipfile, dir = ".") - if (! (nargin == 1 || nargin == 2)) + if (nargin != 1 && nargin != 2) print_usage (); endif - if (nargin == 1) - outputdir = "."; - endif - if (nargout > 0) varargout = cell (1, nargout); - [varargout{:}] = unpack (files, outputdir, mfilename ()); + [varargout{:}] = unpack (zipfile, dir, mfilename ()); else - unpack (files, outputdir, mfilename ()); + unpack (zipfile, dir, mfilename ()); endif endfunction diff --git a/scripts/miscellaneous/ver.m b/scripts/miscellaneous/ver.m --- a/scripts/miscellaneous/ver.m +++ b/scripts/miscellaneous/ver.m @@ -40,19 +40,15 @@ ## Date respecting the version/revision. ## @end table ## @deftypefnx {Function File} {v =} ver (@code{"Octave"}) -## Return version information for Octave only.. -## @deftypefnx {Function File} {v =} ver (@var{pkg}) -## Return version information for the specified package @var{pkg}. +## Return version information for Octave only. +## @deftypefnx {Function File} {v =} ver (@var{package}) +## Return version information for @var{package}. ## @seealso{license, version} ## @end deftypefn ## Author: William Poetra Yoga Hadisoeseno -function varargout = ver (pack) - - if (nargin == 0) - pack = ""; - endif +function varargout = ver (package = "") if (nargin > 1) print_usage (); @@ -93,10 +89,10 @@ pkg ("list"); else - if (! isempty (pack)) + if (! isempty (package)) n = []; for r = 1:numel(ret) - if (strcmpi (ret(r).Name, pack)) + if (strcmpi (ret(r).Name, package)) n = r; break; endif diff --git a/scripts/path/savepath.m b/scripts/path/savepath.m --- a/scripts/path/savepath.m +++ b/scripts/path/savepath.m @@ -27,7 +27,7 @@ ## Author: Bill Denney -function varargout = savepath (savefile) +function varargout = savepath (file) retval = 1; @@ -35,7 +35,7 @@ endstring = "## End savepath auto-created section"; if (nargin == 0) - savefile = fullfile ("~", ".octaverc"); + file = fullfile ("~", ".octaverc"); endif ## parse the file if it exists to see if we should replace a section @@ -43,11 +43,11 @@ startline = 0; endline = 0; filelines = {}; - if (exist (savefile) == 2) + if (exist (file) == 2) ## read in all lines of the file - [fid, msg] = fopen (savefile, "rt"); + [fid, msg] = fopen (file, "rt"); if (fid < 0) - error ("savepath: could not open savefile, %s: %s", savefile, msg); + error ("savepath: could not open file, %s: %s", file, msg); endif unwind_protect linenum = 0; @@ -70,14 +70,14 @@ unwind_protect_cleanup closeread = fclose (fid); if (closeread < 0) - error ("savepath: could not close savefile after reading, %s", - savefile); + error ("savepath: could not close file after reading, %s", + file); endif end_unwind_protect endif if (startline > endline || (startline > 0 && endline == 0)) - error ("savepath: unable to parse file, %s", savefile); + error ("savepath: unable to parse file, %s", file); endif ## put the current savepath lines into the file @@ -102,9 +102,9 @@ endif ## write the results - [fid, msg] = fopen (savefile, "wt"); + [fid, msg] = fopen (file, "wt"); if (fid < 0) - error ("savepath: unable to open file for writing, %s, %s", savefile, msg); + error ("savepath: unable to open file for writing, %s, %s", file, msg); endif unwind_protect for i = 1:length (pre) @@ -193,9 +193,9 @@ unwind_protect_cleanup closeread = fclose (fid); if (closeread < 0) - error ("savepath: could not close savefile after writing, %s", savefile); + error ("savepath: could not close savefile after writing, %s", file); elseif (nargin == 0) - warning ("savepath: current path saved to %s", savefile); + warning ("savepath: current path saved to %s", file); endif end_unwind_protect @@ -209,6 +209,6 @@ function path_elements = parsepath (p) pat = sprintf ('([^%s]+[%s$])', pathsep, pathsep); - [jnk1, jnk2, jnk3, path_elements] = regexpi (strcat (p, pathsep), pat); + [~, ~, ~, path_elements] = regexpi (strcat (p, pathsep), pat); endfunction diff --git a/scripts/plot/allchild.m b/scripts/plot/allchild.m --- a/scripts/plot/allchild.m +++ b/scripts/plot/allchild.m @@ -21,7 +21,7 @@ ## Find all children, including hidden children, of a graphics object. ## ## This function is similar to @code{get (h, "children")}, but also -## returns includes hidden objects. If @var{handles} is a scalar, +## returns hidden objects. If @var{handles} is a scalar, ## @var{h} will be a vector. Otherwise, @var{h} will be a cell matrix ## of the same size as @var{handles} and each cell will contain a ## vector of handles. @@ -30,17 +30,17 @@ ## Author: Bill Denney -function h = allchild (ha) +function h = allchild (handles) shh = get (0, "showhiddenhandles"); unwind_protect set (0, "showhiddenhandles", "on"); - if (isscalar (ha)) - h = get (ha, "children"); + if (isscalar (handles)) + h = get (handles, "children"); else - h = cell (size (ha)); - for i = 1:numel (ha) - h{i} = get (ha, "children"); + h = cell (size (handles)); + for i = 1:numel (handles) + h{i} = get (handles, "children"); endfor endif unwind_protect_cleanup diff --git a/scripts/plot/diffuse.m b/scripts/plot/diffuse.m --- a/scripts/plot/diffuse.m +++ b/scripts/plot/diffuse.m @@ -17,10 +17,10 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} diffuse (@var{sx}, @var{sy}, @var{sz}, @var{l}) +## @deftypefn {Function File} {} diffuse (@var{sx}, @var{sy}, @var{sz}, @var{lv}) ## Calculate diffuse reflection strength of a surface defined by the normal ## vector elements @var{sx}, @var{sy}, @var{sz}. -## The light vector can be specified using parameter @var{L}. It can be +## The light vector can be specified using parameter @var{lv}. It can be ## given as 2-element vector [azimuth, elevation] in degrees or as 3-element ## vector [lx, ly, lz]. ## @seealso{specular, surfl} diff --git a/scripts/plot/fplot.m b/scripts/plot/fplot.m --- a/scripts/plot/fplot.m +++ b/scripts/plot/fplot.m @@ -41,7 +41,7 @@ ## Author: Paul Kienzle -function fplot (fn, limits, n, linespec) +function fplot (fn, limits, n, fmt) if (nargin < 2 || nargin > 4) print_usage (); endif @@ -61,7 +61,7 @@ if (ischar (n)) have_linespec = true; - linespec = n; + fmt = n; n = 0.002; endif @@ -107,7 +107,7 @@ endif if (have_linespec) - plot (x, y, linespec); + plot (x, y, fmt); else plot (x, y); endif diff --git a/scripts/plot/refreshdata.m b/scripts/plot/refreshdata.m --- a/scripts/plot/refreshdata.m +++ b/scripts/plot/refreshdata.m @@ -50,11 +50,11 @@ ## @end example ## @end deftypefn -function refreshdata (h, ws) +function refreshdata (h, workspace) if (nargin == 0) h = gcf (); - ws = "base"; + workspace = "base"; else if (iscell (h)) h = [h{:}]; @@ -63,12 +63,14 @@ error ("refreshdata: expecting a list of figure handles"); endif if (nargin < 2) - ws = "base"; + workspace = "base"; else - if (!ischar (ws) || !(strcmpi (ws, "base") || strcmpi (ws, "caller"))) + if ( !ischar (workspace) + || !(strcmpi (workspace, "base") + || strcmpi (workspace, "caller"))) error ("refreshdata: expecting workspace to be \"base\" or ""caller\""); else - ws = tolower (ws); + workspace = tolower (workspace); endif endif endif @@ -93,7 +95,7 @@ for j = 1 : length (props {i}) expr = get (objs(i), props{i}{j}); if (!isempty (expr)) - val = evalin (ws, expr); + val = evalin (workspace, expr); prop = props{i}{j}(1:end-6); if (! isequal (get (objs(i), prop), val)) set (objs(i), props{i}{j}(1:end-6), val); diff --git a/scripts/plot/saveas.m b/scripts/plot/saveas.m --- a/scripts/plot/saveas.m +++ b/scripts/plot/saveas.m @@ -18,11 +18,11 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} saveas (@var{h}, @var{filename}) -## @deftypefnx {Function File} {} saveas (@var{h}, @var{filename}, @var{ext}) -## Save the graphic object @var{h} to file @var{filename} in graphic -## format @var{ext}. +## @deftypefnx {Function File} {} saveas (@var{h}, @var{filename}, @var{fmt}) +## Save graphic object @var{h} to the file @var{filename} in graphic +## format @var{fmt}. ## -## @var{ext} should be one of the following formats: +## @var{fmt} should be one of the following formats: ## ## @table @code ## @item ps @@ -45,8 +45,8 @@ ## @end table ## ## All device formats specified in @code{print} may also be used. If -## @var{ext} is omitted it is extracted from @var{filename}. The default -## value is pdf. +## @var{fmt} is omitted it is extracted from the extension of @var{filename}. +## The default format is @code{"pdf"}. ## ## @example ## @group @@ -62,7 +62,7 @@ ## Author: Kai Habel -function saveas (h, fname, fext = "pdf") +function saveas (h, filename, fmt = "pdf") if ((nargin != 2) && (nargin != 3)) print_usage (); @@ -78,31 +78,31 @@ error ("saveas: first argument H must be a graphics handle"); endif - if (!ischar (fname)) + if (!ischar (filename)) error ("saveas: FILENAME must be a string"); endif if (nargin == 2) - [~, ~, ext] = fileparts (fname); + [~, ~, ext] = fileparts (filename); if (!isempty (ext)) - fext = ext(2:end); + fmt = ext(2:end); endif endif if (nargin == 3) - if (!ischar (fname)) + if (!ischar (filename)) error ("saveas: EXT must be a string"); endif - [~, ~, ext] = fileparts (fname); + [~, ~, ext] = fileparts (filename); if (isempty (ext)) - fname = strcat (fname, ".", fext); + filename = strcat (filename, ".", fmt); endif endif - prt_opt = strcat ("-d", tolower (fext)); + prt_opt = strcat ("-d", tolower (fmt)); - print (fname, prt_opt); + print (filename, prt_opt); endfunction diff --git a/scripts/plot/specular.m b/scripts/plot/specular.m --- a/scripts/plot/specular.m +++ b/scripts/plot/specular.m @@ -17,12 +17,12 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} specular (@var{sx}, @var{sy}, @var{sz}, @var{l}, @var{v}) -## @deftypefnx {Function File} {} specular (@var{sx}, @var{sy}, @var{sz}, @var{l}, @var{v}, @var{se}) +## @deftypefn {Function File} {} specular (@var{sx}, @var{sy}, @var{sz}, @var{lv}, @var{vv}) +## @deftypefnx {Function File} {} specular (@var{sx}, @var{sy}, @var{sz}, @var{lv}, @var{vv}, @var{se}) ## Calculate specular reflection strength of a surface defined by the normal ## vector elements @var{sx}, @var{sy}, @var{sz} using Phong's approximation. -## The light and view vectors can be specified using parameter @var{L} and -## @var{V} respectively. +## The light and view vectors can be specified using parameter @var{lv} and +## @var{vv} respectively. ## Both can be given as 2-element vectors [azimuth, elevation] in degrees or as ## 3-element ## vector [x, y, z]. An optional 6th argument describes the specular exponent diff --git a/scripts/plot/subplot.m b/scripts/plot/subplot.m --- a/scripts/plot/subplot.m +++ b/scripts/plot/subplot.m @@ -20,7 +20,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} subplot (@var{rows}, @var{cols}, @var{index}) ## @deftypefnx {Function File} {} subplot (@var{rcn}) -## Set up a plot grid with @var{cols} by @var{rows} subwindows and plot +## Set up a plot grid with @var{rows} by @var{cols} subwindows and plot ## in location given by @var{index}. ## ## If only one argument is supplied, then it must be a three digit value @@ -60,7 +60,7 @@ ## Author: Vinayak Dutt ## Adapted-By: jwe -function h = subplot (rows, columns, index, varargin) +function h = subplot (rows, cols, index, varargin) align_axes = false; replace_axes = false; @@ -89,32 +89,32 @@ tmp = rows; index = rem (tmp, 10); tmp = (tmp - index) / 10; - columns = rem (tmp, 10); - tmp = (tmp - columns) / 10; + cols = rem (tmp, 10); + tmp = (tmp - cols) / 10; rows = rem (tmp, 10); - elseif (! (isscalar (columns) && isscalar (rows))) - error ("subplot: columns, and rows must be scalars"); - elseif (any (index < 1) || any (index > rows*columns)) - error ("subplot: index value must be greater than 1 and less than rows*columns") + elseif (! (isscalar (cols) && isscalar (rows))) + error ("subplot: cols, and rows must be scalars"); + elseif (any (index < 1) || any (index > rows*cols)) + error ("subplot: index value must be greater than 1 and less than rows*cols") endif - columns = round (columns); + cols = round (cols); rows = round (rows); index = round (index); - if (index > columns*rows) - error ("subplot: index must be less than columns*rows"); + if (index > cols*rows) + error ("subplot: index must be less than cols*rows"); endif - if (columns < 1 || rows < 1 || index < 1) - error ("subplot: columns,rows,index must be be positive"); + if (cols < 1 || rows < 1 || index < 1) + error ("subplot: cols,rows,index must be be positive"); endif units = get (0, "defaultaxesunits"); unwind_protect set (0, "defaultaxesunits", "normalized") - pos = subplot_position (rows, columns, index, "position", units); + pos = subplot_position (rows, cols, index, "position", units); cf = gcf (); @@ -163,8 +163,8 @@ if (found) set (cf, "currentaxes", tmp); else - pos = subplot_position (rows, columns, index, "outerposition", units); - pos2 = subplot_position (rows, columns, index, "position", units); + pos = subplot_position (rows, cols, index, "outerposition", units); + pos2 = subplot_position (rows, cols, index, "position", units); tmp = axes ("outerposition", pos, "position", pos2, "activepositionproperty", "outerposition"); endif @@ -183,10 +183,10 @@ endfunction -function pos = subplot_position (rows, columns, index, position_property, units) +function pos = subplot_position (rows, cols, index, position_property, units) ## For 1 row and 1 column return the usual default. - if (rows == 1 && columns == 1) + if (rows == 1 && cols == 1) if (strcmpi (position_property, "position")) pos = get (0, "defaultaxesposition"); else @@ -201,13 +201,13 @@ margins.top = 0.075; margins.bottom = 0.110; pc = 1 ./ [0.1860, (margins.left + margins.right - 1)]; - margins.column = 1 ./ polyval (pc , columns); + margins.column = 1 ./ polyval (pc , cols); pr = 1 ./ [0.2282, (margins.top + margins.bottom - 1)]; margins.row = 1 ./ polyval (pr , rows); ## Calculate the width/height of the subplot axes. - width = 1 - margins.left - margins.right - (columns-1)*margins.column; - width = width / columns; + width = 1 - margins.left - margins.right - (cols-1)*margins.column; + width = width / cols; height = 1 - margins.top - margins.bottom - (rows-1)*margins.row; height = height / rows; @@ -220,7 +220,7 @@ inset.bottom = margins.bottom; inset.top = margins.top; endif - if (columns > 1) + if (cols > 1) if (strcmpi (units, "normalized")) inset.right = max (polyval ([0.1200,-0.0014], width), 5/560); else @@ -238,8 +238,8 @@ height = height + inset.top + inset.bottom; endif - yp = fix ((index(:)-1)/columns); - xp = index(:) - yp*columns - 1; + yp = fix ((index(:)-1)/cols); + xp = index(:) - yp*cols - 1; yp = (rows - 1) - yp; x0 = xp .* (width + margins.column) + margins.left; diff --git a/scripts/plot/title.m b/scripts/plot/title.m --- a/scripts/plot/title.m +++ b/scripts/plot/title.m @@ -18,20 +18,20 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} title (@var{title}) -## @deftypefnx {Function File} {} title (@var{title}, @var{p1}, @var{v1}, @dots{}) +## @deftypefn {Function File} {} title (@var{string}) +## @deftypefnx {Function File} {} title (@var{string}, @var{p1}, @var{v1}, @dots{}) ## Create a title object and return a handle to it. ## @end deftypefn ## Author: jwe -function h = title (s, varargin) +function h = title (string, varargin) if (rem (nargin, 2) == 1) if (nargout > 0) - h = __axis_label__ ("title", s, varargin{:}); + h = __axis_label__ ("title", string, varargin{:}); else - __axis_label__ ("title", s, varargin{:}); + __axis_label__ ("title", string, varargin{:}); endif else print_usage (); diff --git a/scripts/plot/uigetdir.m b/scripts/plot/uigetdir.m --- a/scripts/plot/uigetdir.m +++ b/scripts/plot/uigetdir.m @@ -17,36 +17,38 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{dirname} =} uigetdir (@var{init_path}, @var{dialog_name}) +## @deftypefn {Function File} {@var{dirname} =} uigetdir () ## @deftypefnx {Function File} {@var{dirname} =} uigetdir (@var{init_path}) -## @deftypefnx {Function File} {@var{dirname} =} uigetdir () +## @deftypefnx {Function File} {@var{dirname} =} uigetdir (@var{init_path}, @var{dialog_name}) ## Open a GUI dialog to select a directory. If @var{init_path} is not given -## the working directory is taken. @var{dialog_name} can be used to +## the current working directory is used. @var{dialog_name} optionally be used to ## customize the dialog title. ## @end deftypefn ## Author: Kai Habel -function [retdir] = uigetdir (init_path = pwd, name = "Choose directory?") +function dirname = uigetdir (init_path = pwd, dialog_name = "Choose directory?") - if (!ischar(init_path) || !ischar(name)) - error ("uigetdir: expecting string arguments."); - endif - if (nargin > 2) print_usage (); endif - if (any (cellfun(@(x)strcmp (x, "fltk"), available_backends))) + if (!ischar(init_path) || !ischar(name)) + error ("uigetdir: INIT_PATH and DIALOG_NAME must be string arguments"); + endif + + + if (any (strcmp (available_backends(), "fltk"))) if (!isdir (init_path)) init_path = fileparts (init_path); endif - retdir = __fltk_uigetfile__ ("", name, init_path, [240, 120], "dir"); + dirname = __fltk_uigetfile__ ("", dialog_name, init_path, [240, 120], "dir"); else error ("uigetdir: fltk backend required."); endif endfunction + %!demo %! uigetdir(pwd, "Select Directory") diff --git a/scripts/polynomial/polyder.m b/scripts/polynomial/polyder.m --- a/scripts/polynomial/polyder.m +++ b/scripts/polynomial/polyder.m @@ -17,21 +17,22 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} polyder (@var{c}) -## @deftypefnx {Function File} {[@var{q}] =} polyder (@var{b}, @var{a}) -## @deftypefnx {Function File} {[@var{q}, @var{r}] =} polyder (@var{b}, @var{a}) -## See polyderiv. +## @deftypefn {Function File} {} polyderiv (@var{p}) +## @deftypefnx {Function File} {[@var{k}] =} polyderiv (@var{a}, @var{b}) +## @deftypefnx {Function File} {[@var{q}, @var{d}] =} polyderiv (@var{b}, @var{a}) +## An alias for @code{polyderiv}. +## @seealso{polyderiv} ## @end deftypefn ## Author: John W. Eaton -function [q, r] = polyder (p, a) +function [q, d] = polyder (p, a) if (nargin == 1) q = polyderiv (p); elseif (nargin == 2) if (nargout == 2) - [q, r] = polyderiv (p, a); + [q, d] = polyderiv (p, a); else q = polyderiv (p, a); endif diff --git a/scripts/polynomial/polyderiv.m b/scripts/polynomial/polyderiv.m --- a/scripts/polynomial/polyderiv.m +++ b/scripts/polynomial/polyderiv.m @@ -18,14 +18,15 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} polyderiv (@var{c}) -## @deftypefnx {Function File} {[@var{q}] =} polyderiv (@var{b}, @var{a}) -## @deftypefnx {Function File} {[@var{q}, @var{r}] =} polyderiv (@var{b}, @var{a}) +## @deftypefn {Function File} {} polyderiv (@var{p}) +## @deftypefnx {Function File} {[@var{k}] =} polyderiv (@var{a}, @var{b}) +## @deftypefnx {Function File} {[@var{q}, @var{d}] =} polyderiv (@var{b}, @var{a}) ## Return the coefficients of the derivative of the polynomial whose -## coefficients are given by vector @var{c}. If a pair of polynomials -## is given @var{b} and @var{a}, the derivative of the product is -## returned in @var{q}, or the quotient numerator in @var{q} and the -## quotient denominator in @var{r}. +## coefficients are given by the vector @var{p}. If a pair of polynomials +## is given, return the derivative of the product @math{@var{a}*@var{b}}. +## If two inputs and two outputs are given, return the derivative of the +## polynomial quotient @math{@var{b}/@var{a}}. The quotient numerator is +## in @var{q} and the denominator in @var{d}. ## @seealso{poly, polyint, polyreduce, roots, conv, deconv, residue, ## filter, polygcd, polyval, polyvalm} ## @end deftypefn @@ -34,7 +35,7 @@ ## Created: June 1994 ## Adapted-By: jwe -function [q, r] = polyderiv (p, a) +function [q, d] = polyderiv (p, a) if (nargin == 1 || nargin == 2) if (! isvector (p)) @@ -49,7 +50,7 @@ q = polyderiv (conv (p, a)); else ## derivative of p/a returns numerator and denominator - r = conv (a, a); + d = conv (a, a); if (numel (p) == 1) q = -p * polyderiv (a); elseif (numel (a) == 1) @@ -60,15 +61,15 @@ endif ## remove common factors from numerator and denominator - x = polygcd (q, r); + x = polygcd (q, d); if (length(x) != 1) q = deconv (q, x); - r = deconv (r, x); + d = deconv (d, x); endif ## move all the gain into the numerator - q = q/r(1); - r = r/r(1); + q = q/d(1); + d = d/d(1); endif else lp = numel (p); diff --git a/scripts/polynomial/polyint.m b/scripts/polynomial/polyint.m --- a/scripts/polynomial/polyint.m +++ b/scripts/polynomial/polyint.m @@ -17,9 +17,10 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} polyint (@var{c}, @var{k}) +## @deftypefn {Function File} {} polyint (@var{p}) +## @deftypefnx {Function File} {} polyint (@var{p}, @var{k}) ## Return the coefficients of the integral of the polynomial whose -## coefficients are represented by the vector @var{c}. The variable +## coefficients are represented by the vector @var{p}. The variable ## @var{k} is the constant of integration, which by default is set to zero. ## @seealso{poly, polyderiv, polyreduce, roots, conv, deconv, residue, ## filter, polyval, polyvalm} @@ -29,7 +30,7 @@ ## Created: June 1994 ## Adapted-By: jwe -function p = polyint (p, k) +function retval = polyint (p, k) if (nargin < 1 || nargin > 2) print_usage (); @@ -48,7 +49,7 @@ lp = length (p); if (lp == 0) - p = []; + retval = []; return; endif @@ -57,6 +58,6 @@ p = p.'; endif - p = [(p ./ [lp:-1:1]), k]; + retval = [(p ./ [lp:-1:1]), k]; endfunction diff --git a/scripts/polynomial/polyreduce.m b/scripts/polynomial/polyreduce.m --- a/scripts/polynomial/polyreduce.m +++ b/scripts/polynomial/polyreduce.m @@ -29,19 +29,19 @@ ## Created: June 1994 ## Adapted-By: jwe -function p = polyreduce (p) +function p = polyreduce (c) if (nargin != 1) print_usage (); endif - if (! (isvector (p) || isempty (p))) - error ("polyreduce: argument must be a vector"); + if (!isvector (c) || isempty (c)) + error ("polyreduce: C must be a non-empty vector"); endif - if (! isempty (p)) + if (! isempty (c)) - index = find (p != 0); + index = find (c != 0); if (isempty (index)) @@ -49,7 +49,7 @@ else - p = p (index (1):length (p)); + p = c(index (1):length (c)); endif @@ -63,7 +63,5 @@ %!assert(all (all (polyreduce ([1, 0, 3]) == [1, 0, 3]))); -%!assert(isempty (polyreduce ([]))); - %!error polyreduce ([1, 2; 3, 4]); diff --git a/scripts/set/ismember.m b/scripts/set/ismember.m --- a/scripts/set/ismember.m +++ b/scripts/set/ismember.m @@ -18,12 +18,12 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{tf} =} ismember (@var{A}, @var{S}) -## @deftypefnx {Function File} {[@var{tf}, @var{S_idx}] =} ismember (@var{A}, @var{S}) -## @deftypefnx {Function File} {[@var{tf}, @var{S_idx}] =} ismember (@var{A}, @var{S}, "rows") +## @deftypefn {Function File} {@var{tf} =} ismember (@var{A}, @var{s}) +## @deftypefnx {Function File} {[@var{tf}, @var{S_idx}] =} ismember (@var{A}, @var{s}) +## @deftypefnx {Function File} {[@var{tf}, @var{S_idx}] =} ismember (@var{A}, @var{s}, "rows") ## Return a logical matrix @var{tf} with the same shape as @var{A} which is -## true (1) if @code{A(i,j)} is in @var{S} and false (0) if it is not. If a -## second output argument is requested, the index into @var{S} of each of the +## true (1) if @code{A(i,j)} is in @var{s} and false (0) if it is not. If a +## second output argument is requested, the index into @var{s} of each of the ## matching elements is also returned. ## ## @example @@ -36,7 +36,7 @@ ## @end group ## @end example ## -## The inputs, @var{A} and @var{S}, may also be cell arrays. +## The inputs, @var{A} and @var{s}, may also be cell arrays. ## ## @example ## @group @@ -49,8 +49,8 @@ ## @end example ## ## With the optional third argument @code{"rows"}, and matrices -## @var{A} and @var{S} with the same number of columns, compare rows in -## @var{A} with the rows in @var{S}. +## @var{A} and @var{s} with the same number of columns, compare rows in +## @var{A} with the rows in @var{s}. ## ## @example ## @group @@ -71,13 +71,13 @@ ## Adapted-by: jwe ## Reimplemented using lookup & unique: Jaroslav Hajek -function [tf, a_idx] = ismember (a, s, varargin) +function [tf, a_idx] = ismember (A, s, varargin) if (nargin < 2 || nargin > 3) print_usage (); endif - [a, s] = validargs ("ismember", a, s, varargin{:}); + [A, s] = validargs ("ismember", A, s, varargin{:}); if (nargin == 2) s = s(:); @@ -94,25 +94,25 @@ endif if (nargout > 1) - a_idx = lookup (s, a, "m"); + a_idx = lookup (s, A, "m"); tf = logical (a_idx); if (! isempty (is)) a_idx(tf) = is (a_idx(tf)); endif else - tf = lookup (s, a, "b"); + tf = lookup (s, A, "b"); endif else - if (isempty (a) || isempty (s)) - tf = false (rows (a), 1); - a_idx = zeros (rows (a), 1); + if (isempty (A) || isempty (s)) + tf = false (rows (A), 1); + a_idx = zeros (rows (A), 1); else ## FIXME: lookup does not support "rows", so we just use unique. - [xx, ii, jj] = unique ([a; s], "rows", "last"); - na = rows (a); + [xx, ii, jj] = unique ([A; s], "rows", "last"); + na = rows (A); jj = ii(jj(1:na)); tf = jj > na; diff --git a/scripts/signal/arch_fit.m b/scripts/signal/arch_fit.m --- a/scripts/signal/arch_fit.m +++ b/scripts/signal/arch_fit.m @@ -51,7 +51,7 @@ ## Author: KH ## Description: Fit an ARCH regression model -function [a, b] = arch_fit (y, X, p, ITER, gamma, a0, b0) +function [a, b] = arch_fit (y, x, p, iter, gamma, a0, b0) if ((nargin < 3) || (nargin == 6) || (nargin > 7)) print_usage (); @@ -63,26 +63,26 @@ T = length (y); y = reshape (y, T, 1); - [rx, cx] = size (X); + [rx, cx] = size (x); if ((rx == 1) && (cx == 1)) - X = autoreg_matrix (y, X); + x = autoreg_matrix (y, x); elseif (! (rx == T)) - error ("arch_fit: either rows (X) == length (y), or X is a scalar"); + error ("arch_fit: either rows (x) == length (y), or x is a scalar"); endif - [T, k] = size (X); + [T, k] = size (x); if (nargin == 7) a = a0; b = b0; - e = y - X * b; + e = y - x * b; else - [b, v_b, e] = ols (y, X); + [b, v_b, e] = ols (y, x); a = [v_b, (zeros (1, p))]'; if (nargin < 5) gamma = 0.1; if (nargin < 4) - ITER = 50; + iter = 50; endif endif endif @@ -90,7 +90,7 @@ esq = e.^2; Z = autoreg_matrix (esq, p); - for i = 1 : ITER; + for i = 1 : iter; h = Z * a; tmp = esq ./ h.^2 - 1 ./ h; s = 1 ./ h(1:T-p); @@ -102,11 +102,11 @@ r = r + 2 * h(j+1:T-p+j).^2 .* esq(1:T-p); endfor r = sqrt (r); - X_tilde = X(1:T-p, :) .* (r * ones (1,k)); + X_tilde = x(1:T-p, :) .* (r * ones (1,k)); e_tilde = e(1:T-p) .*s ./ r; delta_b = inv (X_tilde' * X_tilde) * X_tilde' * e_tilde; b = b + gamma * delta_b; - e = y - X * b; + e = y - x * b; esq = e .^ 2; Z = autoreg_matrix (esq, p); h = Z * a; diff --git a/scripts/signal/arch_rnd.m b/scripts/signal/arch_rnd.m --- a/scripts/signal/arch_rnd.m +++ b/scripts/signal/arch_rnd.m @@ -41,7 +41,7 @@ ## Author: KH ## Description: Simulate an ARCH process -function y = arch_rnd (a, b, T) +function y = arch_rnd (a, b, t) if (nargin != 3) print_usage (); @@ -50,7 +50,7 @@ if (! ((min (size (a)) == 1) && (min (size (b)) == 1))) error ("arch_rnd: a and b must both be scalars or vectors"); endif - if (! (isscalar (T) && (T > 0) && (rem (T, 1) == 0))) + if (! (isscalar (t) && (t > 0) && (rem (t, 1) == 0))) error ("arch_rnd: T must be a positive integer"); endif @@ -72,17 +72,17 @@ b = [b, 0]; lb = lb + 1; endif - M = max([la, lb]); + m = max([la, lb]); - e = zeros (T, 1); - h = zeros (T, 1); - y = zeros (T, 1); + e = zeros (t, 1); + h = zeros (t, 1); + y = zeros (t, 1); h(1) = a(1); e(1) = sqrt (h(1)) * randn; y(1) = b(1) + e(1); - for t = 2:M + for t = 2:m ta = min ([t, la]); h(t) = a(1) + a(2:ta) * e(t-ta+1:t-1).^2; e(t) = sqrt (h(t)) * randn; @@ -90,14 +90,14 @@ y(t) = b(1) + b(2:tb) * y(t-tb+1:t-1) + e(t); endfor - if (T > M) - for t = M+1:T + if (t > m) + for t = m+1:t h(t) = a(1) + a(2:la) * e(t-la+1:t-1).^2; e(t) = sqrt (h(t)) * randn; y(t) = b(1) + b(2:lb) * y(t-tb+1:t-1) + e(t); endfor endif - y = y(1:T); + y = y(1:t); endfunction diff --git a/scripts/signal/arch_test.m b/scripts/signal/arch_test.m --- a/scripts/signal/arch_test.m +++ b/scripts/signal/arch_test.m @@ -66,7 +66,7 @@ ## Author: KH ## Description: Test for conditional heteroscedascity -function [pval, lm] = arch_test (y, X, p) +function [pval, lm] = arch_test (y, x, p) if (nargin != 3) error ("arch_test: 3 input arguments required"); @@ -77,9 +77,9 @@ endif T = length (y); y = reshape (y, T, 1); - [rx, cx] = size (X); + [rx, cx] = size (x); if ((rx == 1) && (cx == 1)) - X = autoreg_matrix (y, X); + x = autoreg_matrix (y, x); elseif (! (rx == T)) error ("arch_test: either rows(X) == length(y), or X is a scalar"); endif @@ -87,7 +87,7 @@ error ("arch_test: p must be a positive integer"); endif - [b, v_b, e] = ols (y, X); + [b, v_b, e] = ols (y, x); Z = autoreg_matrix (e.^2, p); f = e.^2 / v_b - ones (T, 1); f = Z' * f; diff --git a/scripts/signal/diffpara.m b/scripts/signal/diffpara.m --- a/scripts/signal/diffpara.m +++ b/scripts/signal/diffpara.m @@ -40,17 +40,17 @@ ## Author: FL ## Description: Estimate the fractional differencing parameter -function [d, D] = diffpara (X, a, b) +function [d, dd] = diffpara (x, a, b) if ((nargin < 1) || (nargin > 3)) print_usage (); else - if (isvector (X)) - n = length (X); + if (isvector (x)) + n = length (x); k = 1; - X = reshape (X, n, 1); + x = reshape (x, n, 1); else - [n, k] = size(X); + [n, k] = size(x); endif if (nargin == 1) a = 0.5 * sqrt (n); @@ -65,25 +65,25 @@ error ("diffpara: a and b must be scalars"); endif - D = zeros (b - a + 1, k); + dd = zeros (b - a + 1, k); for l = 1:k w = 2 * pi * (1 : n-1) / n; x = 2 * log (abs (1 - exp (-i*w))); - y = log (periodogram (X(2:n,l))); + y = log (periodogram (x(2:n,l))); x = center (x); y = center (y); for m = a:b - D(m-a+1) = - x(1:m) * y(1:m) / sumsq (x(1:m)); + dd(m-a+1) = - x(1:m) * y(1:m) / sumsq (x(1:m)); endfor endfor - d = mean (D); + d = mean (dd); endfunction diff --git a/scripts/signal/fftconv.m b/scripts/signal/fftconv.m --- a/scripts/signal/fftconv.m +++ b/scripts/signal/fftconv.m @@ -18,13 +18,13 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} fftconv (@var{a}, @var{b}) -## @deftypefnx {Function File} {} fftconv (@var{a}, @var{b}, @var{n}) +## @deftypefn {Function File} {} fftconv (@var{x}, @var{y}) +## @deftypefnx {Function File} {} fftconv (@var{x}, @var{y}, @var{n}) ## Convolve two vectors using the FFT for computation. ## -## @code{c = fftconv (@var{a}, @var{b})} returns a vector of length equal to -## @code{length (@var{a}) + length (@var{b}) - 1}. -## If @var{a} and @var{b} are the coefficient vectors of two polynomials, the +## @code{c = fftconv (@var{x}, @var{y})} returns a vector of length equal to +## @code{length (@var{x}) + length (@var{y}) - 1}. +## If @var{x} and @var{y} are the coefficient vectors of two polynomials, the ## returned value is the coefficient vector of the product polynomial. ## ## The computation uses the FFT by calling the function @code{fftfilt}. If @@ -36,35 +36,36 @@ ## Created: 3 September 1994 ## Adapted-By: jwe -function c = fftconv (a, b, N) +function c = fftconv (x, y, n) if (nargin < 2 || nargin > 3) print_usage (); endif - if (! (isvector (a) && isvector (b))) + if (! (isvector (x) && isvector (y))) error ("fftconv: both A and B must be vectors"); endif - la = length (a); - lb = length (b); + la = length (x); + lb = length (y); if ((la == 1) || (lb == 1)) - c = a * b; + c = x * y; else lc = la + lb - 1; - a(lc) = 0; - b(lc) = 0; + x(lc) = 0; + y(lc) = 0; if (nargin == 2) - c = fftfilt (a, b); + c = fftfilt (x, y); else - if (! isscalar (N)) + if (! isscalar (n)) error ("fftconv: N must be a scalar"); endif - c = fftfilt (a, b, N); + c = fftfilt (x, y, n); endif endif endfunction + %% FIXME: Borrow tests from conv.m. May need a tolerance on the assert comparison %!test %! x = ones(3,1); diff --git a/scripts/signal/fftfilt.m b/scripts/signal/fftfilt.m --- a/scripts/signal/fftfilt.m +++ b/scripts/signal/fftfilt.m @@ -33,7 +33,7 @@ ## Created: 3 September 1994 ## Adapted-By: jwe -function y = fftfilt (b, x, N) +function y = fftfilt (b, x, n) ## If N is not specified explicitly, we do not use the overlap-add ## method at all because loops are really slow. Otherwise, we only @@ -64,27 +64,27 @@ if (nargin == 2) ## Use FFT with the smallest power of 2 which is >= length (x) + ## length (b) - 1 as number of points ... - N = 2 ^ (ceil (log (r_x + l_b - 1) / log (2))); - B = fft (b, N); - y = ifft (fft (x, N) .* B(:,ones (1, c_x))); + n = 2 ^ (ceil (log (r_x + l_b - 1) / log (2))); + B = fft (b, n); + y = ifft (fft (x, n) .* B(:,ones (1, c_x))); else ## Use overlap-add method ... - if (! (isscalar (N))) - error ("fftfilt: N has to be a scalar"); + if (! (isscalar (n))) + error ("fftfilt: n has to be a scalar"); endif - N = 2 ^ (ceil (log (max ([N, l_b])) / log (2))); - L = N - l_b + 1; - B = fft (b, N); + n = 2 ^ (ceil (log (max ([n, l_b])) / log (2))); + L = n - l_b + 1; + B = fft (b, n); B = B(:,ones (c_x,1)); R = ceil (r_x / L); y = zeros (r_x, c_x); for r = 1:R; lo = (r - 1) * L + 1; hi = min (r * L, r_x); - tmp = zeros (N, c_x); + tmp = zeros (n, c_x); tmp(1:(hi-lo+1),:) = x(lo:hi,:); tmp = ifft (fft (tmp) .* B); - hi = min (lo+N-1, r_x); + hi = min (lo+n-1, r_x); y(lo:hi,:) = y(lo:hi,:) + tmp(1:(hi-lo+1),:); endfor endif diff --git a/scripts/signal/fftshift.m b/scripts/signal/fftshift.m --- a/scripts/signal/fftshift.m +++ b/scripts/signal/fftshift.m @@ -18,22 +18,22 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} fftshift (@var{v}) -## @deftypefnx {Function File} {} fftshift (@var{v}, @var{dim}) -## Perform a shift of the vector @var{v}, for use with the @code{fft} +## @deftypefn {Function File} {} fftshift (@var{x}) +## @deftypefnx {Function File} {} fftshift (@var{x}, @var{dim}) +## Perform a shift of the vector @var{x}, for use with the @code{fft} ## and @code{ifft} functions, in order the move the frequency 0 to the ## center of the vector or matrix. ## -## If @var{v} is a vector of @math{N} elements corresponding to @math{N} +## If @var{x} is a vector of @math{N} elements corresponding to @math{N} ## time samples spaced of @math{Dt} each, then @code{fftshift (fft -## (@var{v}))} corresponds to frequencies +## (@var{x}))} corresponds to frequencies ## ## @example ## f = ((1:N) - ceil(N/2)) / N / Dt ## @end example ## -## If @var{v} is a matrix, the same holds for rows and columns. If -## @var{v} is an array, then the same holds along each dimension. +## If @var{x} is a matrix, the same holds for rows and columns. If +## @var{x} is an array, then the same holds along each dimension. ## ## The optional @var{dim} argument can be used to limit the dimension ## along which the permutation occurs. @@ -43,7 +43,7 @@ ## Created: July 1997 ## Adapted-By: jwe -function retval = fftshift (V, dim) +function retval = fftshift (x, dim) retval = 0; @@ -55,29 +55,29 @@ if (!isscalar (dim)) error ("fftshift: dimension must be an integer scalar"); endif - nd = ndims (V); - sz = size (V); + nd = ndims (x); + sz = size (x); sz2 = ceil (sz(dim) / 2); idx = cell (); for i = 1:nd idx{i} = 1:sz(i); endfor idx{dim} = [sz2+1:sz(dim), 1:sz2]; - retval = V (idx{:}); + retval = x(idx{:}); else - if (isvector (V)) - x = length (V); + if (isvector (x)) + x = length (x); xx = ceil (x/2); - retval = V([xx+1:x, 1:xx]); - elseif (ismatrix (V)) - nd = ndims (V); - sz = size (V); + retval = x([xx+1:x, 1:xx]); + elseif (ismatrix (x)) + nd = ndims (x); + sz = size (x); sz2 = ceil (sz ./ 2); idx = cell (); for i = 1:nd idx{i} = [sz2(i)+1:sz(i), 1:sz2(i)]; endfor - retval = V (idx{:}); + retval = x(idx{:}); else error ("fftshift: expecting vector or matrix argument"); endif diff --git a/scripts/signal/filter2.m b/scripts/signal/filter2.m --- a/scripts/signal/filter2.m +++ b/scripts/signal/filter2.m @@ -43,7 +43,7 @@ ## 2001-02-08 ## * initial release -function Y = filter2 (B, X, shape) +function y = filter2 (b, x, shape) if (nargin < 2 || nargin > 3) print_usage (); @@ -52,6 +52,7 @@ shape = "same"; endif - [nr, nc] = size(B); - Y = conv2 (X, B(nr:-1:1, nc:-1:1), shape); + [nr, nc] = size(b); + y = conv2 (x, b(nr:-1:1, nc:-1:1), shape); endfunction + diff --git a/scripts/signal/ifftshift.m b/scripts/signal/ifftshift.m --- a/scripts/signal/ifftshift.m +++ b/scripts/signal/ifftshift.m @@ -17,10 +17,10 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} ifftshift (@var{v}) -## @deftypefnx {Function File} {} ifftshift (@var{v}, @var{dim}) +## @deftypefn {Function File} {} ifftshift (@var{x}) +## @deftypefnx {Function File} {} ifftshift (@var{x}, @var{dim}) ## Undo the action of the @code{fftshift} function. For even length -## @var{v}, @code{fftshift} is its own inverse, but odd lengths differ +## @var{x}, @code{fftshift} is its own inverse, but odd lengths differ ## slightly. ## @end deftypefn @@ -30,7 +30,7 @@ ## Modified-By: Paul Kienzle, converted from fftshift ## Modified-By: David Bateman, add NDArray capability and option dim arg -function retval = ifftshift (V, dim) +function retval = ifftshift (x, dim) retval = 0; @@ -42,29 +42,29 @@ if (! isscalar (dim)) error ("ifftshift: dimension must be an integer scalar"); endif - nd = ndims (V); - sz = size (V); + nd = ndims (x); + sz = size (x); sz2 = floor (sz(dim) / 2); idx = cell (); for i = 1:nd idx{i} = 1:sz(i); endfor idx{dim} = [sz2+1:sz(dim), 1:sz2]; - retval = V (idx{:}); + retval = x(idx{:}); else - if (isvector (V)) - x = length (V); + if (isvector (x)) + x = length (x); xx = floor (x/2); - retval = V([xx+1:x, 1:xx]); - elseif (ismatrix (V)) - nd = ndims (V); - sz = size (V); + retval = x([xx+1:x, 1:xx]); + elseif (ismatrix (x)) + nd = ndims (x); + sz = size (x); sz2 = floor (sz ./ 2); idx = cell (); for i = 1:nd idx{i} = [sz2(i)+1:sz(i), 1:sz2(i)]; endfor - retval = V (idx{:}); + retval = x(idx{:}); else error ("ifftshift: expecting vector or matrix argument"); endif diff --git a/scripts/signal/sinetone.m b/scripts/signal/sinetone.m --- a/scripts/signal/sinetone.m +++ b/scripts/signal/sinetone.m @@ -29,39 +29,40 @@ ## Author: FL ## Description: Compute a sine tone -function retval = sinetone (f, r, s, a) +function retval = sinetone (freq, rate, sec, ampl) if (nargin == 1) - r = 8000; - s = 1; - a = 64; + rate = 8000; + sec = 1; + ampl = 64; elseif (nargin == 2) - s = 1; - a = 64; + sec = 1; + ampl = 64; elseif (nargin == 3) - a = 64; + ampl = 64; elseif ((nargin < 1) || (nargin > 4)) print_usage (); endif - [err, f, a] = common_size (f, a); - if (err || ! isvector (f)) + [err, freq, ampl] = common_size (freq, ampl); + if (err || ! isvector (freq)) error ("sinetone: freq and ampl must be vectors of common size"); endif - if (! (isscalar (r) && isscalar (s))) + if (! (isscalar (rate) && isscalar (sec))) error ("sinetone: rate and sec must be scalars"); endif - n = length (f); - ns = round (r * s); + n = length (freq); + ns = round (rate * sec); retval = zeros (ns, n); for k = 1:n - retval (:, k) = a(k) * sin (2 * pi * (1:ns) / r * f(k))'; + retval (:, k) = ampl(k) * sin (2 * pi * (1:ns) / rate * freq(k))'; endfor endfunction + %!assert (size (sinetone (18e6, 150e6, 19550/150e6, 1)), [19550, 1]); diff --git a/scripts/signal/spectral_xdf.m b/scripts/signal/spectral_xdf.m --- a/scripts/signal/spectral_xdf.m +++ b/scripts/signal/spectral_xdf.m @@ -32,12 +32,12 @@ ## Author: FL ## Description: Spectral density estimation -function retval = spectral_xdf (X, win, b) +function retval = spectral_xdf (x, win, b) - xr = length (X); + xr = length (x); - if (columns (X) > 1) - X = X'; + if (columns (x) > 1) + x = x'; endif if (nargin < 3) @@ -51,9 +51,9 @@ w = feval (win, xr, b); endif - X = X - sum (X) / xr; + x = x - sum (x) / xr; - retval = (abs (fft (X)) / xr).^2; + retval = (abs (fft (x)) / xr).^2; retval = real (ifft (fft(retval) .* fft(w))); retval = [(zeros (xr, 1)), retval]; @@ -61,10 +61,3 @@ endfunction - - - - - - - diff --git a/scripts/signal/spencer.m b/scripts/signal/spencer.m --- a/scripts/signal/spencer.m +++ b/scripts/signal/spencer.m @@ -19,46 +19,36 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} spencer (@var{x}) -## Return Spencer's 15 point moving average of every single column of +## Return Spencer's 15 point moving average of each column of ## @var{x}. ## @end deftypefn ## Author: FL ## Description: Apply Spencer's 15-point MA filter -function retval = spencer (X) +function retval = spencer (x) if (nargin != 1) print_usage (); endif - [xr, xc] = size(X); + [xr, xc] = size(x); n = xr; c = xc; - if (isvector(X)) - n = length(X); + if (isvector(x)) + n = length(x); c = 1; - X = reshape(X, n, 1); + x = reshape(x, n, 1); endif - W = [-3, -6, -5, 3, 21, 46, 67, 74, 67, 46, 21, 3, -5, -6, -3] / 320; + w = [-3, -6, -5, 3, 21, 46, 67, 74, 67, 46, 21, 3, -5, -6, -3] / 320; - retval = fftfilt (W, X); + retval = fftfilt (w, x); retval = [zeros(7,c); retval(15:n,:); zeros(7,c);]; retval = reshape(retval, xr, xc); endfunction - - - - - - - - - - diff --git a/scripts/signal/stft.m b/scripts/signal/stft.m --- a/scripts/signal/stft.m +++ b/scripts/signal/stft.m @@ -18,7 +18,7 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{y}, @var{c}] =} stft (@var{x}, @var{win_size}, @var{inc}, @var{num_coef}, @var{w_type}) +## @deftypefn {Function File} {[@var{y}, @var{c}] =} stft (@var{x}, @var{win_size}, @var{inc}, @var{num_coef}, @var{win_type}) ## Compute the short-time Fourier transform of the vector @var{x} with ## @var{num_coef} coefficients by applying a window of @var{win_size} data ## points and an increment of @var{inc} points. @@ -28,20 +28,20 @@ ## ## @table @asis ## @item @nospell{hanning} -## w_type = 1 +## win_type = 1 ## ## @item @nospell{hamming} -## w_type = 2 +## win_type = 2 ## ## @item rectangle -## w_type = 3 +## win_type = 3 ## @end table ## -## The window names can be passed as strings or by the @var{w_type} number. +## The window names can be passed as strings or by the @var{win_type} number. ## ## If not all arguments are specified, the following defaults are used: ## @var{win_size} = 80, @var{inc} = 24, @var{num_coef} = 64, and -## @var{w_type} = 1. +## @var{win_type} = 1. ## ## @code{@var{y} = stft (@var{x}, @dots{})} returns the absolute values ## of the Fourier coefficients according to the @var{num_coef} positive @@ -56,30 +56,30 @@ ## Author: AW ## Description: Short-Time Fourier Transform -function [Y, c] = stft(X, win, inc, coef, w_type) +function [y, c] = stft(x, win_size, inc, num_coef, win_type) ## Default values of unspecified arguments. if (nargin < 5) - w_type = 1; + win_type = 1; if (nargin < 4) - coef = 64; + num_coef = 64; if (nargin < 3) inc = 24; if (nargin < 2) - win = 80; + win_size = 80; endif endif endif elseif (nargin == 5) - if (ischar (w_type)) - if (strcmp (w_type, "hanning")) - w_type = 1; - elseif (strcmp (w_type, "hamming")) - w_type = 2; - elseif (strcmp (w_type, "rectangle")) - w_type = 3; + if (ischar (win_type)) + if (strcmp (win_type, "hanning")) + win_type = 1; + elseif (strcmp (win_type, "hamming")) + win_type = 2; + elseif (strcmp (win_type, "rectangle")) + win_type = 3; else - error ("stft: unknown window type `%s'", w_type); + error ("stft: unknown window type `%s'", win_type); endif endif else @@ -87,49 +87,49 @@ endif ## Check whether X is a vector. - [nr, nc] = size (X); + [nr, nc] = size (x); if (nc != 1) if (nr == 1) - X = X'; + x = x'; nr = nc; else error ("stft: X must be a vector"); endif endif - num_coef = 2 * coef; - if (win > num_coef) - win = num_coef; - printf ("stft: window size adjusted to %f\n", win); + ncoef = 2 * num_coef; + if (win_size > ncoef) + win_size = ncoef; + printf ("stft: window size adjusted to %f\n", win_size); endif - num_win = fix ((nr - win) / inc); + num_win = fix ((nr - win_size) / inc); ## compute the window coefficients - if (w_type == 3) + if (win_type == 3) ## Rectangular window. - WIN_COEF = ones (win, 1); - elseif (w_type == 2) + win_coef = ones (win_size, 1); + elseif (win_type == 2) ## Hamming window. - WIN_COEF = hamming (win); + win_coef = hamming (win_size); else ## Hanning window. - WIN_COEF = hanning (win); + win_coef = hanning (win_size); endif ## Create a matrix Z whose columns contain the windowed time-slices. - Z = zeros (num_coef, num_win + 1); + z = zeros (ncoef, num_win + 1); start = 1; for i = 0:num_win - Z(1:win, i+1) = X(start:start+win-1) .* WIN_COEF; + z(1:win_size, i+1) = x(start:start+win_size-1) .* win_coef; start = start + inc; endfor - Y = fft (Z); + y = fft (z); if (nargout == 1) - Y = abs (Y(1:coef, :)); + y = abs (y(1:num_coef, :)); else - c = [win, inc, w_type]; + c = [win_size, inc, win_type]; endif endfunction diff --git a/scripts/signal/synthesis.m b/scripts/signal/synthesis.m --- a/scripts/signal/synthesis.m +++ b/scripts/signal/synthesis.m @@ -33,7 +33,7 @@ ## Author: AW ## Description: Recover a signal from its short-term Fourier transform -function X = synthesis (Y, c) +function x = synthesis (y, c) if (nargin != 2) print_usage (); @@ -44,31 +44,30 @@ error ("synthesis: c must contain exactly 3 elements"); endif - ## not necessary, enables better reading - win = c(1); - inc = c(2); + w_size = c(1); + inc = c(2); w_type = c(3); if (w_type == 1) - H = hanning (win); + w_coeff = hanning (w_size); elseif (w_type == 2) - H = hamming (win); + w_coeff = hamming (w_size); elseif (w_type == 3) - H = ones (win, 1); + w_coeff = ones (w_size, 1); else error ("synthesis: window_type must be 1, 2, or 3"); endif - Z = real (ifft (Y)); - st = fix ((win-inc) / 2); - Z = Z(st:st+inc-1, :); - H = H(st:st+inc-1); + z = real (ifft (y)); + st = fix ((w_size-inc) / 2); + z = z(st:st+inc-1, :); + w_coeff = w_coeff(st:st+inc-1); - nc = columns(Z); + nc = columns(z); for i = 1:nc - Z(:, i) = Z(:, i) ./ H; + z(:, i) = z(:, i) ./ w_coeff; endfor - X = reshape(Z, inc * nc, 1); + x = reshape(z, inc * nc, 1); endfunction diff --git a/scripts/sparse/etreeplot.m b/scripts/sparse/etreeplot.m --- a/scripts/sparse/etreeplot.m +++ b/scripts/sparse/etreeplot.m @@ -17,20 +17,20 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} etreeplot (@var{tree}) -## @deftypefnx {Function File} {} etreeplot (@var{tree}, @var{node_style}, @var{edge_style}) -## Plot the elimination tree of the matrix @var{s} or -## @code{@var{s}+@var{s}'} if @var{s} in non-symmetric. The optional -## parameters @var{line_style} and @var{edge_style} define the output +## @deftypefn {Function File} {} etreeplot (@var{A}) +## @deftypefnx {Function File} {} etreeplot (@var{A}, @var{node_style}, @var{edge_style}) +## Plot the elimination tree of the matrix @var{A} or +## @code{@var{A}+@var{A}'} if @var{A} in not symmetric. The optional +## parameters @var{node_style} and @var{edge_style} define the output ## style. ## @seealso{treeplot, gplot} ## @end deftypefn -function etreeplot (s, varargin) +function etreeplot (A, varargin) if (nargin < 1) print_usage (); endif - treeplot (etree (s+s'), varargin{:}); + treeplot (etree (A+A'), varargin{:}); endfunction diff --git a/scripts/sparse/spfun.m b/scripts/sparse/spfun.m --- a/scripts/sparse/spfun.m +++ b/scripts/sparse/spfun.m @@ -18,27 +18,27 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{y} =} spfun (@var{f},@var{x}) -## Compute @code{f(@var{x})} for the non-zero values of @var{x}. +## @deftypefn {Function File} {@var{y} =} spfun (@var{f},@var{S}) +## Compute @code{f(@var{S})} for the non-zero values of @var{S}. ## This results in a sparse matrix with the same structure as -## @var{x}. The function @var{f} can be passed as a string, a +## @var{S}. The function @var{f} can be passed as a string, a ## function handle, or an inline function. ## @seealso{arrayfun, cellfun, structfun} ## @end deftypefn -function t = spfun (f, s) +function y = spfun (f, S) if (nargin != 2) print_usage (); endif - [i, j, v] = find (s); - [m, n] = size (s); + [i, j, v] = find (S); + [m, n] = size (S); if (isa (f, "function_handle") || isa (f, "inline function")) - t = sparse (i, j, f(v), m, n); + y = sparse (i, j, f(v), m, n); else - t = sparse(i, j, feval (f, v), m, n); + y = sparse(i, j, feval (f, v), m, n); endif endfunction diff --git a/scripts/sparse/spones.m b/scripts/sparse/spones.m --- a/scripts/sparse/spones.m +++ b/scripts/sparse/spones.m @@ -17,21 +17,21 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{y} =} spones (@var{x}) -## Replace the non-zero entries of @var{x} with ones. This creates a -## sparse matrix with the same structure as @var{x}. +## @deftypefn {Function File} {@var{r} =} spones (@var{S}) +## Replace the non-zero entries of @var{S} with ones. This creates a +## sparse matrix with the same structure as @var{S}. ## @end deftypefn -function s = spones (s) +function r = spones (S) if (nargin != 1) print_usage (); endif - [i, j, v] = find (s); - [m, n] = size (s); + [i, j, v] = find (S); + [m, n] = size (S); - s = sparse (i, j, 1, m, n); + r = sparse (i, j, 1, m, n); endfunction diff --git a/scripts/sparse/spstats.m b/scripts/sparse/spstats.m --- a/scripts/sparse/spstats.m +++ b/scripts/sparse/spstats.m @@ -17,17 +17,17 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{count}, @var{mean}, @var{var}] =} spstats (@var{s}) -## @deftypefnx {Function File} {[@var{count}, @var{mean}, @var{var}] =} spstats (@var{s}, @var{j}) -## Return the stats for the non-zero elements of the sparse matrix @var{s}. +## @deftypefn {Function File} {[@var{count}, @var{mean}, @var{var}] =} spstats (@var{S}) +## @deftypefnx {Function File} {[@var{count}, @var{mean}, @var{var}] =} spstats (@var{S}, @var{j}) +## Return the stats for the non-zero elements of the sparse matrix @var{S}. ## @var{count} is the number of non-zeros in each column, @var{mean} ## is the mean of the non-zeros in each column, and @var{var} is the ## variance of the non-zeros in each column. ## -## Called with two input arguments, if @var{s} is the data and @var{j} +## Called with two input arguments, if @var{S} is the data and @var{j} ## is the bin number for the data, compute the stats for each bin. In ## this case, bins can contain data values of zero, whereas with -## @code{spstats (@var{s})} the zeros may disappear. +## @code{spstats (@var{S})} the zeros may disappear. ## @end deftypefn function [count, mean, var] = spstats (S, j) @@ -57,6 +57,7 @@ endfunction + %!test %! [n,m,v] = spstats([1 2 1 2 3 4],[2 2 1 1 1 1]); %! assert(n,sparse([4,2])); diff --git a/scripts/sparse/treelayout.m b/scripts/sparse/treelayout.m --- a/scripts/sparse/treelayout.m +++ b/scripts/sparse/treelayout.m @@ -17,9 +17,9 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} treelayout (@var{Tree}) -## @deftypefnx {Function File} {} treelayout (@var{Tree}, @var{permutation}) -## treelayout lays out a tree or a forest. The first argument @var{Tree} is a +## @deftypefn {Function File} {} treelayout (@var{tree}) +## @deftypefnx {Function File} {} treelayout (@var{tree}, @var{permutation}) +## treelayout lays out a tree or a forest. The first argument @var{tree} is a ## vector of ## predecessors, optional parameter @var{permutation} is an optional postorder ## permutation. diff --git a/scripts/sparse/treeplot.m b/scripts/sparse/treeplot.m --- a/scripts/sparse/treeplot.m +++ b/scripts/sparse/treeplot.m @@ -18,9 +18,9 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} treeplot (@var{tree}) -## @deftypefnx {Function File} {} treeplot (@var{tree}, @var{line_style}, @var{edge_style}) +## @deftypefnx {Function File} {} treeplot (@var{tree}, @var{node_style}, @var{edge_style}) ## Produces a graph of tree or forest. The first argument is vector of -## predecessors, optional parameters @var{line_style} and @var{edge_style} +## predecessors, optional parameters @var{node_style} and @var{edge_style} ## define the output style. The complexity of the algorithm is O(n) in ## terms of is time and memory requirements. ## @seealso{etreeplot, gplot} diff --git a/scripts/specfun/factor.m b/scripts/specfun/factor.m --- a/scripts/specfun/factor.m +++ b/scripts/specfun/factor.m @@ -20,9 +20,9 @@ ## @deftypefn {Function File} {@var{p} =} factor (@var{q}) ## @deftypefnx {Function File} {[@var{p}, @var{n}] =} factor (@var{q}) ## -## Return prime factorization of @var{q}. That is, @code{prod (@var{p}) -## == @var{q}} and every element of @var{p} is a prime number. If -## @code{@var{q} == 1}, returns 1. +## Return prime factorization of @var{q}. That is, +## @code{prod (@var{p}) == @var{q}} and every element of @var{p} is a prime +## number. If @code{@var{q} == 1}, return 1. ## ## With two output arguments, return the unique primes @var{p} and ## their multiplicities. That is, @code{prod (@var{p} .^ @var{n}) == @@ -37,39 +37,39 @@ ## * return multiplicity as suggested by Dirk Laurie ## * add error handling -function [x, m] = factor (n) +function [x, n] = factor (q) if (nargin < 1) print_usage (); endif - if (! isscalar (n) || n != fix (n)) - error ("factor: n must be a scalar integer"); + if (! isscalar (q) || q != fix (q)) + error ("factor: q must be a scalar integer"); endif - ## Special case of no primes less than sqrt(n). - if (n < 4) - x = n; - m = 1; + ## Special case of no primes less than sqrt(q). + if (q < 4) + x = q; + n = 1; return; endif x = []; - ## There is at most one prime greater than sqrt(n), and if it exists, + ## There is at most one prime greater than sqrt(q), and if it exists, ## it has multiplicity 1, so no need to consider any factors greater - ## than sqrt(n) directly. [If there were two factors p1, p2 > sqrt(n), - ## then n >= p1*p2 > sqrt(n)*sqrt(n) == n. Contradiction.] - p = primes (sqrt (n)); - while (n > 1) - ## Find prime factors in remaining n. - p = p (rem (n, p) == 0); + ## than sqrt(q) directly. [If there were two factors p1, p2 > sqrt(q), + ## then q >= p1*p2 > sqrt(q)*sqrt(q) == q. Contradiction.] + p = primes (sqrt (q)); + while (q > 1) + ## Find prime factors in remaining q. + p = p (rem (q, p) == 0); if (isempty (p)) - ## Can't be reduced further, so n must itself be a prime. - p = n; + ## Can't be reduced further, so q must itself be a prime. + p = q; endif x = [x, p]; - ## Reduce n. - n = n / prod (p); + ## Reduce q. + q = q / prod (p); endwhile x = sort (x); @@ -77,18 +77,19 @@ if (nargout > 1) idx = find ([0, x] != [x, 0]); x = x(idx(1:length(idx)-1)); - m = diff (idx); + n = diff (idx); endif endfunction -## test: -## assert(factor(1),1); -## for i=2:20 -## p = factor(i); -## assert(prod(p),i); -## assert(all(isprime(p))); -## [p,n] = factor(i); -## assert(prod(p.^n),i); -## assert(all([0,p]!=[p,0])); -## end +%!test +%! assert(factor(1),1); +%! for i=2:20 +%! p = factor(i); +%! assert(prod(p),i); +%! assert(all(isprime(p))); +%! [p,n] = factor(i); +%! assert(prod(p.^n),i); +%! assert(all([0,p]!=[p,0])); +%! endfor + diff --git a/scripts/specfun/isprime.m b/scripts/specfun/isprime.m --- a/scripts/specfun/isprime.m +++ b/scripts/specfun/isprime.m @@ -34,20 +34,20 @@ ## @seealso{primes, factor, gcd, lcm} ## @end deftypefn -function t = isprime (n) +function t = isprime (x) if (nargin == 1) - if (any ((n != floor (n) | n < 0)(:))) + if (any ((x != floor (x) | x < 0)(:))) error ("isprime: needs positive integers"); endif - maxn = max (n(:)); + maxn = max (x(:)); ## generate prime table of suitable length. maxp = min (maxn, max (sqrt (maxn), 1e7)); # FIXME: threshold not optimized. pr = primes (maxp); ## quick search for table matches. - t = lookup (pr, n, "b"); + t = lookup (pr, x, "b"); ## take the rest. - m = n(n > maxp); + m = x(x > maxp); if (! isempty (m)) ## there are still possible primes. filter them out by division. if (maxn <= intmax ("uint32")) @@ -68,8 +68,8 @@ mm = arrayfun (@(x) all (rem (x, pr)), m); m = m(mm); if (! isempty (m)) - m = cast (sort (m), class (n)); - t |= lookup (m, n, "b"); + m = cast (sort (m), class (x)); + t |= lookup (m, x, "b"); endif endif @@ -79,6 +79,7 @@ endfunction + %!assert (isprime (4), logical (0)); %!assert (isprime (3), logical (1)); %!assert (isprime (magic (3)), logical ([0, 0, 0; 1, 1, 1; 0, 0, 1])); diff --git a/scripts/specfun/primes.m b/scripts/specfun/primes.m --- a/scripts/specfun/primes.m +++ b/scripts/specfun/primes.m @@ -24,7 +24,7 @@ ## The algorithm used is the Sieve of Eratosthenes. ## ## Note that if you need a specific number of primes you can use the -## fact the distance from one prime to the next is, on average, +## fact that the distance from one prime to the next is, on average, ## proportional to the logarithm of the prime. Integrating, one finds ## that there are about @math{k} primes less than ## @tex @@ -40,28 +40,28 @@ ## Author: Francesco Potort́ ## Author: Dirk Laurie -function x = primes (p) +function x = primes (n) if (nargin != 1) print_usage (); endif - if (! isscalar (p)) + if (! isscalar (n)) error ("primes: n must be a scalar"); endif - if (p > 100000) + if (n > 100000) ## Optimization: 1/6 less memory, and much faster (asymptotically) ## 100000 happens to be the cross-over point for Paul's machine; ## below this the more direct code below is faster. At the limit ## of memory in Paul's machine, this saves .7 seconds out of 7 for - ## p = 3e6. Hardly worthwhile, but Dirk reports better numbers. - lenm = floor ((p+1)/6); # length of the 6n-1 sieve - lenp = floor ((p-1)/6); # length of the 6n+1 sieve + ## n = 3e6. Hardly worthwhile, but Dirk reports better numbers. + lenm = floor ((n+1)/6); # length of the 6n-1 sieve + lenp = floor ((n-1)/6); # length of the 6n+1 sieve sievem = true (1, lenm); # assume every number of form 6n-1 is prime sievep = true (1, lenp); # assume every number of form 6n+1 is prime - for i = 1:(sqrt(p)+1)/6 # check up to sqrt(p) + for i = 1:(sqrt(n)+1)/6 # check up to sqrt(n) if (sievem(i)) # if i is prime, eliminate multiples of i sievem(7*i-1:6*i-1:lenm) = false; sievep(5*i-1:6*i-1:lenp) = false; @@ -72,10 +72,10 @@ endif endfor x = sort([2, 3, 6*find(sievem)-1, 6*find(sievep)+1]); - elseif (p > 352) # nothing magical about 352; must be >2 - len = floor ((p-1)/2); # length of the sieve + elseif (n > 352) # nothing magical about 352; must be >2 + len = floor ((n-1)/2); # length of the sieve sieve = true (1, len); # assume every odd number is prime - for i = 1:(sqrt(p)-1)/2 # check up to sqrt(p) + for i = 1:(sqrt(n)-1)/2 # check up to sqrt(n) if (sieve(i)) # if i is prime, eliminate multiples of i sieve(3*i+1:2*i+1:len) = false; # do it endif @@ -88,7 +88,7 @@ 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, ... 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, ... 293, 307, 311, 313, 317, 331, 337, 347, 349]; - x = a(a <= p); + x = a(a <= n); endif endfunction diff --git a/scripts/statistics/distributions/cauchy_cdf.m b/scripts/statistics/distributions/cauchy_cdf.m --- a/scripts/statistics/distributions/cauchy_cdf.m +++ b/scripts/statistics/distributions/cauchy_cdf.m @@ -18,11 +18,11 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} cauchy_cdf (@var{x}, @var{lambda}, @var{sigma}) +## @deftypefn {Function File} {} cauchy_cdf (@var{x}, @var{location}, @var{scale}) ## For each element of @var{x}, compute the cumulative distribution ## function (CDF) at @var{x} of the Cauchy distribution with location -## parameter @var{lambda} and scale parameter @var{sigma}. Default -## values are @var{lambda} = 0, @var{sigma} = 1. +## parameter @var{location} and scale parameter @var{scale}. Default +## values are @var{location} = 0, @var{scale} = 1. ## @end deftypefn ## Author: KH @@ -42,7 +42,7 @@ if (!isscalar (location) || !isscalar (scale)) [retval, x, location, scale] = common_size (x, location, scale); if (retval > 0) - error ("cauchy_cdf: x, lambda and sigma must be of common size or scalar"); + error ("cauchy_cdf: x, location and scale must be of common size or scalar"); endif endif diff --git a/scripts/statistics/distributions/cauchy_inv.m b/scripts/statistics/distributions/cauchy_inv.m --- a/scripts/statistics/distributions/cauchy_inv.m +++ b/scripts/statistics/distributions/cauchy_inv.m @@ -18,11 +18,11 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} cauchy_inv (@var{x}, @var{lambda}, @var{sigma}) +## @deftypefn {Function File} {} cauchy_inv (@var{x}, @var{location}, @var{scale}) ## For each element of @var{x}, compute the quantile (the inverse of the ## CDF) at @var{x} of the Cauchy distribution with location parameter -## @var{lambda} and scale parameter @var{sigma}. Default values are -## @var{lambda} = 0, @var{sigma} = 1. +## @var{location} and scale parameter @var{scale}. Default values are +## @var{location} = 0, @var{scale} = 1. ## @end deftypefn ## Author: KH @@ -42,7 +42,7 @@ if (!isscalar (location) || !isscalar (scale)) [retval, x, location, scale] = common_size (x, location, scale); if (retval > 0) - error ("cauchy_inv: x, lambda and sigma must be of common size or scalar"); + error ("cauchy_inv: x, location and scale must be of common size or scalar"); endif endif diff --git a/scripts/statistics/distributions/cauchy_pdf.m b/scripts/statistics/distributions/cauchy_pdf.m --- a/scripts/statistics/distributions/cauchy_pdf.m +++ b/scripts/statistics/distributions/cauchy_pdf.m @@ -18,11 +18,11 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} cauchy_pdf (@var{x}, @var{lambda}, @var{sigma}) +## @deftypefn {Function File} {} cauchy_pdf (@var{x}, @var{location}, @var{scale}) ## For each element of @var{x}, compute the probability density function ## (PDF) at @var{x} of the Cauchy distribution with location parameter -## @var{lambda} and scale parameter @var{sigma} > 0. Default values are -## @var{lambda} = 0, @var{sigma} = 1. +## @var{location} and scale parameter @var{scale} > 0. Default values are +## @var{location} = 0, @var{scale} = 1. ## @end deftypefn ## Author: KH @@ -42,7 +42,7 @@ if (!isscalar (location) || !isscalar (scale)) [retval, x, location, scale] = common_size (x, location, scale); if (retval > 0) - error ("cauchy_pdf: x, lambda and sigma must be of common size or scalar"); + error ("cauchy_pdf: x, location and scale must be of common size or scalar"); endif endif diff --git a/scripts/statistics/distributions/cauchy_rnd.m b/scripts/statistics/distributions/cauchy_rnd.m --- a/scripts/statistics/distributions/cauchy_rnd.m +++ b/scripts/statistics/distributions/cauchy_rnd.m @@ -18,26 +18,26 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} cauchy_rnd (@var{lambda}, @var{sigma}, @var{r}, @var{c}) -## @deftypefnx {Function File} {} cauchy_rnd (@var{lambda}, @var{sigma}, @var{sz}) +## @deftypefn {Function File} {} cauchy_rnd (@var{location}, @var{scale}, @var{r}, @var{c}) +## @deftypefnx {Function File} {} cauchy_rnd (@var{location}, @var{scale}, @var{sz}) ## Return an @var{r} by @var{c} or a @code{size (@var{sz})} matrix of -## random samples from the Cauchy distribution with parameters @var{lambda} -## and @var{sigma} which must both be scalar or of size @var{r} by @var{c}. +## random samples from the Cauchy distribution with parameters @var{location} +## and @var{scale} which must both be scalar or of size @var{r} by @var{c}. ## ## If @var{r} and @var{c} are omitted, the size of the result matrix is -## the common size of @var{lambda} and @var{sigma}. +## the common size of @var{location} and @var{scale}. ## @end deftypefn ## Author: KH ## Description: Random deviates from the Cauchy distribution -function rnd = cauchy_rnd (l, scale, r, c) +function rnd = cauchy_rnd (location, scale, r, c) if (nargin > 1) - if (!isscalar (l) || !isscalar (scale)) - [retval, l, scale] = common_size (l, scale); + if (!isscalar (location) || !isscalar (scale)) + [retval, location, scale] = common_size (location, scale); if (retval > 0) - error ("cauchy_rnd: lambda and sigma must be of common size or scalar"); + error ("cauchy_rnd: location and scale must be of common size or scalar"); endif endif endif @@ -51,9 +51,10 @@ endif sz = [r, c]; - if (any (size (l) != 1) - && (length (size (l)) != length (sz) || any (size (l) != sz))) - error ("cauchy_rnd: lambda and sigma must be scalar or of size [r, c]"); + if (any (size (location) != 1) + && (length (size (location)) != length (sz) + || any (size (location) != sz))) + error ("cauchy_rnd: location and scale must be scalar or of size [r, c]"); endif elseif (nargin == 3) if (isscalar (r) && (r > 0)) @@ -64,27 +65,30 @@ error ("cauchy_rnd: r must be a positive integer or vector"); endif - if (any (size (l) != 1) - && (length (size (l)) != length (sz) || any (size (l) != sz))) - error ("cauchy_rnd: lambda and sigma must be scalar or of size sz"); + if (any (size (location) != 1) + && (length (size (location)) != length (sz) + || any (size (location) != sz))) + error ("cauchy_rnd: location and scale must be scalar or of size sz"); endif elseif (nargin == 2) - sz = size(l); + sz = size(location); else print_usage (); endif - if (isscalar (l) && isscalar (scale)) - if (find (!(l > -Inf) | !(l < Inf) | !(scale > 0) | !(scale < Inf))) + if (isscalar (location) && isscalar (scale)) + if (find (!(location > -Inf) | !(location < Inf) + | !(scale > 0) | !(scale < Inf))) rnd = NaN (sz); else - rnd = l - cot (pi * rand (sz)) .* scale; + rnd = location - cot (pi * rand (sz)) .* scale; endif else rnd = NaN (sz); - k = find ((l > -Inf) & (l < Inf) & (scale > 0) & (scale < Inf)); + k = find ((location > -Inf) & (location < Inf) + & (scale > 0) & (scale < Inf)); if (any (k)) - rnd(k) = l(k)(:) - cot (pi * rand (size (k))) .* scale(k)(:); + rnd(k) = location(k)(:) - cot (pi * rand (size (k))) .* scale(k)(:); endif endif diff --git a/scripts/statistics/distributions/expcdf.m b/scripts/statistics/distributions/expcdf.m --- a/scripts/statistics/distributions/expcdf.m +++ b/scripts/statistics/distributions/expcdf.m @@ -28,45 +28,45 @@ ## Author: KH ## Description: CDF of the exponential distribution -function cdf = expcdf (x, l) +function cdf = expcdf (x, lambda) if (nargin != 2) print_usage (); endif - if (!isscalar (x) && !isscalar(l)) - [retval, x, l] = common_size (x, l); + if (!isscalar (x) && !isscalar(lambda)) + [retval, x, lambda] = common_size (x, lambda); if (retval > 0) error ("expcdf: x and lambda must be of common size or scalar"); endif endif if (isscalar (x)) - sz = size (l); + sz = size (lambda); else sz = size (x); endif cdf = zeros (sz); - k = find (isnan (x) | !(l > 0)); + k = find (isnan (x) | !(lambda > 0)); if (any (k)) cdf(k) = NaN; endif - k = find ((x == Inf) & (l > 0)); + k = find ((x == Inf) & (lambda > 0)); if (any (k)) cdf(k) = 1; endif - k = find ((x > 0) & (x < Inf) & (l > 0)); + k = find ((x > 0) & (x < Inf) & (lambda > 0)); if (any (k)) - if isscalar (l) - cdf (k) = 1 - exp (- x(k) ./ l); + if isscalar (lambda) + cdf (k) = 1 - exp (- x(k) ./ lambda); elseif isscalar (x) - cdf (k) = 1 - exp (- x ./ l(k)); + cdf (k) = 1 - exp (- x ./ lambda(k)); else - cdf (k) = 1 - exp (- x(k) ./ l(k)); + cdf (k) = 1 - exp (- x(k) ./ lambda(k)); endif endif diff --git a/scripts/statistics/distributions/expinv.m b/scripts/statistics/distributions/expinv.m --- a/scripts/statistics/distributions/expinv.m +++ b/scripts/statistics/distributions/expinv.m @@ -26,45 +26,45 @@ ## Author: KH ## Description: Quantile function of the exponential distribution -function inv = expinv (x, l) +function inv = expinv (x, lambda) if (nargin != 2) print_usage (); endif - if (!isscalar (x) && !isscalar(l)) - [retval, x, l] = common_size (x, l); + if (!isscalar (x) && !isscalar(lambda)) + [retval, x, lambda] = common_size (x, lambda); if (retval > 0) error ("expinv: x and lambda must be of common size or scalar"); endif endif if (isscalar (x)) - sz = size (l); + sz = size (lambda); else sz = size (x); endif inv = zeros (sz); - k = find (!(l > 0) | (x < 0) | (x > 1) | isnan (x)); + k = find (!(lambda > 0) | (x < 0) | (x > 1) | isnan (x)); if (any (k)) inv(k) = NaN; endif - k = find ((x == 1) & (l > 0)); + k = find ((x == 1) & (lambda > 0)); if (any (k)) inv(k) = Inf; endif - k = find ((x > 0) & (x < 1) & (l > 0)); + k = find ((x > 0) & (x < 1) & (lambda > 0)); if (any (k)) - if isscalar (l) - inv(k) = - l .* log (1 - x(k)); + if isscalar (lambda) + inv(k) = - lambda .* log (1 - x(k)); elseif isscalar (x) - inv(k) = - l(k) .* log (1 - x); + inv(k) = - lambda(k) .* log (1 - x); else - inv(k) = - l(k) .* log (1 - x(k)); + inv(k) = - lambda(k) .* log (1 - x(k)); endif endif diff --git a/scripts/statistics/distributions/exppdf.m b/scripts/statistics/distributions/exppdf.m --- a/scripts/statistics/distributions/exppdf.m +++ b/scripts/statistics/distributions/exppdf.m @@ -25,39 +25,39 @@ ## Author: KH ## Description: PDF of the exponential distribution -function pdf = exppdf (x, l) +function pdf = exppdf (x, lambda) if (nargin != 2) print_usage (); endif - if (!isscalar (x) && !isscalar(l)) - [retval, x, l] = common_size (x, l); + if (!isscalar (x) && !isscalar(lambda)) + [retval, x, lambda] = common_size (x, lambda); if (retval > 0) error ("exppdf: x and lambda must be of common size or scalar"); endif endif if (isscalar (x)) - sz = size (l); + sz = size (lambda); else sz = size (x); endif pdf = zeros (sz); - k = find (!(l > 0) | isnan (x)); + k = find (!(lambda > 0) | isnan (x)); if (any (k)) pdf(k) = NaN; endif - k = find ((x > 0) & (x < Inf) & (l > 0)); + k = find ((x > 0) & (x < Inf) & (lambda > 0)); if (any (k)) - if isscalar (l) - pdf(k) = exp (- x(k) ./ l) ./ l; + if isscalar (lambda) + pdf(k) = exp (- x(k) ./ lambda) ./ lambda; elseif isscalar (x) - pdf(k) = exp (- x ./ l(k)) ./ l(k); + pdf(k) = exp (- x ./ lambda(k)) ./ lambda(k); else - pdf(k) = exp (- x(k) ./ l(k)) ./ l(k); + pdf(k) = exp (- x(k) ./ lambda(k)) ./ lambda(k); endif endif diff --git a/scripts/statistics/distributions/exprnd.m b/scripts/statistics/distributions/exprnd.m --- a/scripts/statistics/distributions/exprnd.m +++ b/scripts/statistics/distributions/exprnd.m @@ -31,7 +31,7 @@ ## Author: KH ## Description: Random deviates from the exponential distribution -function rnd = exprnd (l, r, c) +function rnd = exprnd (lambda, r, c) if (nargin == 3) if (! (isscalar (r) && (r > 0) && (r == round (r)))) @@ -42,8 +42,8 @@ endif sz = [r, c]; - if (any (size (l) != 1) - && (length (size (l)) != length (sz) || any (size (l) != sz))) + if (any (size (lambda) != 1) + && (length (size (lambda)) != length (sz) || any (size (lambda) != sz))) error ("exprnd: lambda must be scalar or of size [r, c]"); endif elseif (nargin == 2) @@ -55,32 +55,32 @@ error ("exprnd: r must be a positive integer or vector"); endif - if (any (size (l) != 1) - && ((length (size (l)) != length (sz)) || any (size (l) != sz))) + if (any (size (lambda) != 1) + && ((length (size (lambda)) != length (sz)) || any (size (lambda) != sz))) error ("exprnd: lambda must be scalar or of size sz"); endif elseif (nargin == 1) - sz = size (l); + sz = size (lambda); else print_usage (); endif - if (isscalar (l)) - if ((l > 0) && (l < Inf)) - rnd = rande(sz) * l; + if (isscalar (lambda)) + if ((lambda > 0) && (lambda < Inf)) + rnd = rande(sz) * lambda; else rnd = NaN (sz); endif else rnd = zeros (sz); - k = find (!(l > 0) | !(l < Inf)); + k = find (!(lambda > 0) | !(lambda < Inf)); if (any (k)) rnd(k) = NaN; endif - k = find ((l > 0) & (l < Inf)); + k = find ((lambda > 0) & (lambda < Inf)); if (any (k)) - rnd(k) = rande(size(k)) .* l(k); + rnd(k) = rande(size(k)) .* lambda(k); endif endif diff --git a/scripts/statistics/distributions/poisscdf.m b/scripts/statistics/distributions/poisscdf.m --- a/scripts/statistics/distributions/poisscdf.m +++ b/scripts/statistics/distributions/poisscdf.m @@ -26,14 +26,14 @@ ## Author: KH ## Description: CDF of the Poisson distribution -function cdf = poisscdf (x, l) +function cdf = poisscdf (x, lambda) if (nargin != 2) print_usage (); endif - if (!isscalar (l)) - [retval, x, l] = common_size (x, l); + if (!isscalar (lambda)) + [retval, x, lambda] = common_size (x, lambda); if (retval > 0) error ("poisscdf: x and lambda must be of common size or scalar"); endif @@ -41,22 +41,22 @@ cdf = zeros (size (x)); - k = find (isnan (x) | !(l > 0)); + k = find (isnan (x) | !(lambda > 0)); if (any (k)) cdf(k) = NaN; endif - k = find ((x == Inf) & (l > 0)); + k = find ((x == Inf) & (lambda > 0)); if (any (k)) cdf(k) = 1; endif - k = find ((x >= 0) & (x < Inf) & (l > 0)); + k = find ((x >= 0) & (x < Inf) & (lambda > 0)); if (any (k)) - if (isscalar (l)) - cdf(k) = 1 - gammainc (l, floor (x(k)) + 1); + if (isscalar (lambda)) + cdf(k) = 1 - gammainc (lambda, floor (x(k)) + 1); else - cdf(k) = 1 - gammainc (l(k), floor (x(k)) + 1); + cdf(k) = 1 - gammainc (lambda(k), floor (x(k)) + 1); endif endif diff --git a/scripts/statistics/distributions/poissinv.m b/scripts/statistics/distributions/poissinv.m --- a/scripts/statistics/distributions/poissinv.m +++ b/scripts/statistics/distributions/poissinv.m @@ -26,14 +26,14 @@ ## Author: KH ## Description: Quantile function of the Poisson distribution -function inv = poissinv (x, l) +function inv = poissinv (x, lambda) if (nargin != 2) print_usage (); endif - if (!isscalar (l)) - [retval, x, l] = common_size (x, l); + if (!isscalar (lambda)) + [retval, x, lambda] = common_size (x, lambda); if (retval > 0) error ("poissinv: x and lambda must be of common size or scalar"); endif @@ -41,31 +41,31 @@ inv = zeros (size (x)); - k = find ((x < 0) | (x > 1) | isnan (x) | !(l > 0)); + k = find ((x < 0) | (x > 1) | isnan (x) | !(lambda > 0)); if (any (k)) inv(k) = NaN; endif - k = find ((x == 1) & (l > 0)); + k = find ((x == 1) & (lambda > 0)); if (any (k)) inv(k) = Inf; endif - k = find ((x > 0) & (x < 1) & (l > 0)); + k = find ((x > 0) & (x < 1) & (lambda > 0)); if (any (k)) - if (isscalar (l)) - cdf = exp (-l) * ones (size (k)); + if (isscalar (lambda)) + cdf = exp (-lambda) * ones (size (k)); else - cdf = exp (-l(k)); + cdf = exp (-lambda(k)); endif while (1) m = find (cdf < x(k)); if (any (m)) inv(k(m)) = inv(k(m)) + 1; - if (isscalar (l)) - cdf(m) = cdf(m) + poisspdf (inv(k(m)), l); + if (isscalar (lambda)) + cdf(m) = cdf(m) + poisspdf (inv(k(m)), lambda); else - cdf(m) = cdf(m) + poisspdf (inv(k(m)), l(k(m))); + cdf(m) = cdf(m) + poisspdf (inv(k(m)), lambda(k(m))); endif else break; diff --git a/scripts/statistics/distributions/poisspdf.m b/scripts/statistics/distributions/poisspdf.m --- a/scripts/statistics/distributions/poisspdf.m +++ b/scripts/statistics/distributions/poisspdf.m @@ -25,14 +25,14 @@ ## Author: KH ## Description: PDF of the Poisson distribution -function pdf = poisspdf (x, l) +function pdf = poisspdf (x, lambda) if (nargin != 2) print_usage (); endif - if (!isscalar (l)) - [retval, x, l] = common_size (x, l); + if (!isscalar (lambda)) + [retval, x, lambda] = common_size (x, lambda); if (retval > 0) error ("poisspdf: x and lambda must be of common size or scalar"); endif @@ -40,17 +40,17 @@ pdf = zeros (size (x)); - k = find (!(l > 0) | isnan (x)); + k = find (!(lambda > 0) | isnan (x)); if (any (k)) pdf(k) = NaN; endif - k = find ((x >= 0) & (x < Inf) & (x == round (x)) & (l > 0)); + k = find ((x >= 0) & (x < Inf) & (x == round (x)) & (lambda > 0)); if (any (k)) - if (isscalar (l)) - pdf(k) = exp (x(k) .* log (l) - l - gammaln (x(k) + 1)); + if (isscalar (lambda)) + pdf(k) = exp (x(k) .* log (lambda) - lambda - gammaln (x(k) + 1)); else - pdf(k) = exp (x(k) .* log (l(k)) - l(k) - gammaln (x(k) + 1)); + pdf(k) = exp (x(k) .* log (lambda(k)) - lambda(k) - gammaln (x(k) + 1)); endif endif diff --git a/scripts/statistics/distributions/poissrnd.m b/scripts/statistics/distributions/poissrnd.m --- a/scripts/statistics/distributions/poissrnd.m +++ b/scripts/statistics/distributions/poissrnd.m @@ -29,7 +29,7 @@ ## Author: KH ## Description: Random deviates from the Poisson distribution -function rnd = poissrnd (l, r, c) +function rnd = poissrnd (lambda, r, c) if (nargin == 3) if (! (isscalar (r) && (r > 0) && (r == round (r)))) @@ -40,8 +40,8 @@ endif sz = [r, c]; - if (any (size (l) != 1) - && ((length (size (l)) != length (sz)) || any (size (l) != sz))) + if (any (size (lambda) != 1) + && ((length (size (lambda)) != length (sz)) || any (size (lambda) != sz))) error ("poissrnd: lambda must be scalar or of size [r, c]"); endif elseif (nargin == 2) @@ -53,36 +53,36 @@ error ("poissrnd: r must be a positive integer or vector"); endif - if (any (size (l) != 1) - && ((length (size (l)) != length (sz)) || any (size (l) != sz))) + if (any (size (lambda) != 1) + && ((length (size (lambda)) != length (sz)) || any (size (lambda) != sz))) error ("poissrnd: lambda must be scalar or of size sz"); endif elseif (nargin == 1) - sz = size (l); + sz = size (lambda); else print_usage (); endif - if (isscalar (l)) + if (isscalar (lambda)) - if (!(l >= 0) || !(l < Inf)) + if (!(lambda >= 0) || !(lambda < Inf)) rnd = NaN (sz); - elseif (l > 0 && l < Inf) - rnd = randp(l, sz); + elseif (lambda > 0 && lambda < Inf) + rnd = randp(lambda, sz); else rnd = zeros (sz); endif else rnd = zeros (sz); - k = find (!(l >= 0) | !(l < Inf)); + k = find (!(lambda >= 0) | !(lambda < Inf)); if (any (k)) rnd(k) = NaN; endif - k = find ((l > 0) & (l < Inf)); + k = find ((lambda > 0) & (lambda < Inf)); if (any (k)) - rnd(k) = randp(l(k), size(k)); + rnd(k) = randp(lambda(k), size(k)); endif endif diff --git a/scripts/statistics/tests/chisquare_test_independence.m b/scripts/statistics/tests/chisquare_test_independence.m --- a/scripts/statistics/tests/chisquare_test_independence.m +++ b/scripts/statistics/tests/chisquare_test_independence.m @@ -33,18 +33,18 @@ ## Author: KH ## Description: Chi-square test for independence -function [pval, chisq, df] = chisquare_test_independence (X) +function [pval, chisq, df] = chisquare_test_independence (x) if (nargin != 1) print_usage (); endif - [r, s] = size (X); + [r, s] = size (x); df = (r - 1) * (s - 1); - n = sum (sum (X)); - Y = sum (X')' * sum (X) / n; - X = (X - Y) .^2 ./ Y; - chisq = sum (sum (X)); + n = sum (sum (x)); + y = sum (x')' * sum (x) / n; + x = (x - y) .^2 ./ y; + chisq = sum (sum (x)); pval = 1 - chi2cdf (chisq, df); if (nargout == 0) diff --git a/scripts/statistics/tests/cor_test.m b/scripts/statistics/tests/cor_test.m --- a/scripts/statistics/tests/cor_test.m +++ b/scripts/statistics/tests/cor_test.m @@ -27,8 +27,8 @@ ## @code{">"} (greater than 0), or @code{"<"} (less than 0). The ## default is the two-sided case. ## -## The optional argument string @var{method} specifies on which -## correlation coefficient the test should be based. If @var{method} is +## The optional argument string @var{method} specifies which +## correlation coefficient to use for testing. If @var{method} is ## @code{"pearson"} (default), the (usual) Pearson's product moment ## correlation coefficient is used. In this case, the data should come ## from a bivariate normal distribution. Otherwise, the other two @@ -66,33 +66,33 @@ ## Adapted-by: KH ## Description: Test for zero correlation -function t = cor_test (X, Y, ALTERNATIVE, METHOD) +function t = cor_test (x, y, alt, method) if ((nargin < 2) || (nargin > 4)) print_usage (); endif - if (!isvector (X) || !isvector (Y) || length (X) != length (Y)) + if (!isvector (x) || !isvector (y) || length (x) != length (y)) error ("cor_test: X and Y must be vectors of the same length"); endif if (nargin < 3) - ALTERNATIVE = "!="; - elseif (! ischar (ALTERNATIVE)) - error ("cor_test: ALTERNATIVE must be a string"); + alt = "!="; + elseif (! ischar (alt)) + error ("cor_test: alt must be a string"); endif if (nargin < 4) - METHOD = "pearson"; - elseif (! ischar (METHOD)) + method = "pearson"; + elseif (! ischar (method)) error ("cor_test: METHOD must be a string"); endif - n = length (X); - m = METHOD (1); + n = length (x); + m = method (1); if (m == "p") - r = cor (X, Y); + r = cor (x, y); df = n - 2; t.method = "Pearson's product moment correlation"; t.params = df; @@ -100,34 +100,34 @@ t.dist = "t"; cdf = tcdf (t.stat, df); elseif (m == "k") - tau = kendall (X, Y); + tau = kendall (x, y); t.method = "Kendall's rank correlation tau"; t.params = []; t.stat = tau / sqrt ((2 * (2*n+5)) / (9*n*(n-1))); t.dist = "stdnormal"; cdf = stdnormal_cdf (t.stat); elseif (m == "s") - rho = spearman (X, Y); + rho = spearman (x, y); t.method = "Spearman's rank correlation rho"; t.params = []; t.stat = sqrt (n-1) * (rho - 6/(n^3-n)); t.dist = "stdnormal"; cdf = stdnormal_cdf (t.stat); else - error ("cor_test: method `%s' not recognized", METHOD); + error ("cor_test: method `%s' not recognized", method); endif - if (strcmp (ALTERNATIVE, "!=") || strcmp (ALTERNATIVE, "<>")) + if (strcmp (alt, "!=") || strcmp (alt, "<>")) t.pval = 2 * min (cdf, 1 - cdf); - elseif (strcmp (ALTERNATIVE, ">")) + elseif (strcmp (alt, ">")) t.pval = 1 - cdf; - elseif (strcmp (ALTERNATIVE, "<")) + elseif (strcmp (alt, "<")) t.pval = cdf; else - error ("cor_test: alternative `%s' not recognized", ALTERNATIVE); + error ("cor_test: alternative `%s' not recognized", alt); endif - t.alternative = ALTERNATIVE; + t.alternative = alt; if (nargout == 0) printf ("pval: %g\n", t.pval); diff --git a/scripts/statistics/tests/f_test_regression.m b/scripts/statistics/tests/f_test_regression.m --- a/scripts/statistics/tests/f_test_regression.m +++ b/scripts/statistics/tests/f_test_regression.m @@ -36,27 +36,27 @@ ## Author: KH ## Description: Test linear hypotheses in linear regression model -function [pval, f, df_num, df_den] = f_test_regression (y, X, R, r) +function [pval, f, df_num, df_den] = f_test_regression (y, x, rr, r) if (nargin < 3 || nargin > 4) print_usage (); endif - [T, k] = size (X); + [T, k] = size (x); if (! (isvector (y) && (length (y) == T))) error ("f_test_regression: y must be a vector of length rows (X)"); endif y = reshape (y, T, 1); - [q, c_R ] = size (R); + [q, c_R ] = size (rr); if (c_R != k) - error ("f_test_regression: R must have as many columns as X"); + error ("f_test_regression: rr must have as many columns as x"); endif if (nargin == 4) s_r = size (r); if ((min (s_r) != 1) || (max (s_r) != q)) - error ("f_test_regression: r must be a vector of length rows (R)"); + error ("f_test_regression: r must be a vector of length rows (rr)"); endif r = reshape (r, q, 1); else @@ -66,9 +66,9 @@ df_num = q; df_den = T - k; - [b, v] = ols (y, X); - diff = R * b - r; - f = diff' * inv (R * inv (X' * X) * R') * diff / (q * v); + [b, v] = ols (y, x); + diff = rr * b - r; + f = diff' * inv (rr * inv (x' * x) * rr') * diff / (q * v); pval = 1 - f_cdf (f, df_num, df_den); if (nargout == 0) diff --git a/scripts/statistics/tests/manova.m b/scripts/statistics/tests/manova.m --- a/scripts/statistics/tests/manova.m +++ b/scripts/statistics/tests/manova.m @@ -18,14 +18,14 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} manova (@var{y}, @var{g}) +## @deftypefn {Function File} {} manova (@var{x}, @var{g}) ## Perform a one-way multivariate analysis of variance (MANOVA). The ## goal is to test whether the p-dimensional population means of data ## taken from @var{k} different groups are all equal. All data are ## assumed drawn independently from p-dimensional normal distributions ## with the same covariance matrix. ## -## The data matrix is given by @var{y}. As usual, rows are observations +## The data matrix is given by @var{x}. As usual, rows are observations ## and columns are variables. The vector @var{g} specifies the ## corresponding group labels (e.g., numbers from 1 to @var{k}). ## @@ -41,17 +41,17 @@ ## Adapted-By: KH ## Description: One-way multivariate analysis of variance (MANOVA) -function manova (Y, g) +function manova (x, g) if (nargin != 2) print_usage (); endif - if (isvector (Y)) + if (isvector (x)) error ("manova: Y must not be a vector"); endif - [n, p] = size (Y); + [n, p] = size (x); if (!isvector (g) || (length (g) != n)) error ("manova: g must be a vector of length rows (Y)"); @@ -67,13 +67,13 @@ group_label = s ([1, (reshape (i, 1, k - 1) + 1)]); endif - Y = Y - ones (n, 1) * mean (Y); - SST = Y' * Y; + x = x - ones (n, 1) * mean (x); + SST = x' * x; s = zeros (1, p); SSB = zeros (p, p); for i = 1 : k; - v = Y (find (g == group_label (i)), :); + v = x (find (g == group_label (i)), :); s = sum (v); SSB = SSB + s' * s / rows (v); endfor diff --git a/scripts/statistics/tests/t_test_regression.m b/scripts/statistics/tests/t_test_regression.m --- a/scripts/statistics/tests/t_test_regression.m +++ b/scripts/statistics/tests/t_test_regression.m @@ -42,7 +42,7 @@ ## Author: KH ## Description: Test one linear hypothesis in linear regression model -function [pval, t, df] = t_test_regression (y, X, R, r, alt) +function [pval, t, df] = t_test_regression (y, x, rr, r, alt) if (nargin == 3) r = 0; @@ -64,20 +64,20 @@ error ("t_test_regression: alt must be a string"); endif - [T, k] = size (X); + [T, k] = size (x); if (! (isvector (y) && (length (y) == T))) error ("t_test_regression: y must be a vector of length rows (X)"); endif - s = size (R); + s = size (rr); if (! ((max (s) == k) && (min (s) == 1))) - error ("t_test_regression: R must be a vector of length columns (X)"); + error ("t_test_regression: rr must be a vector of length columns (X)"); endif - R = reshape (R, 1, k); + rr = reshape (rr, 1, k); y = reshape (y, T, 1); - [b, v] = ols (y, X); + [b, v] = ols (y, x); df = T - k; - t = (R * b - r) / sqrt (v * R * inv (X' * X) * R'); + t = (rr * b - r) / sqrt (v * rr * inv (x' * x) * rr'); cdf = tcdf (t, df); if (strcmp (alt, "!=") || strcmp (alt, "<>")) diff --git a/scripts/strings/base2dec.m b/scripts/strings/base2dec.m --- a/scripts/strings/base2dec.m +++ b/scripts/strings/base2dec.m @@ -17,8 +17,8 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} base2dec (@var{s}, @var{b}) -## Convert @var{s} from a string of digits in base @var{b} to a decimal +## @deftypefn {Function File} {} base2dec (@var{s}, @var{base}) +## Convert @var{s} from a string of digits in base @var{base} to a decimal ## integer (base 10). ## ## @example @@ -33,7 +33,7 @@ ## corresponding value will be NaN@. Rows are right-justified before ## converting so that trailing spaces are ignored. ## -## If @var{b} is a string, the characters of @var{b} are used as the +## If @var{base} is a string, the characters of @var{base} are used as the ## symbols for the digits of @var{s}. Space (' ') may not be used as a ## symbol. ## diff --git a/scripts/strings/dec2base.m b/scripts/strings/dec2base.m --- a/scripts/strings/dec2base.m +++ b/scripts/strings/dec2base.m @@ -17,9 +17,9 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} dec2base (@var{d}, @var{b}) -## @deftypefnx {Function File} {} dec2base (@var{d}, @var{b}, @var{len}) -## Return a string of symbols in base @var{b} corresponding to +## @deftypefn {Function File} {} dec2base (@var{d}, @var{base}) +## @deftypefnx {Function File} {} dec2base (@var{d}, @var{base}, @var{len}) +## Return a string of symbols in base @var{base} corresponding to ## the non-negative integer @var{d}. ## ## @example @@ -32,7 +32,7 @@ ## If @var{d} is a vector, return a string matrix with one row per value, ## padded with leading zeros to the width of the largest value. ## -## If @var{b} is a string then the characters of @var{b} are used as +## If @var{base} is a string then the characters of @var{base} are used as ## the symbols for the digits of @var{d}. Space (' ') may not be used ## as a symbol. ## diff --git a/scripts/strings/regexptranslate.m b/scripts/strings/regexptranslate.m --- a/scripts/strings/regexptranslate.m +++ b/scripts/strings/regexptranslate.m @@ -51,7 +51,7 @@ ## @seealso{regexp, regexpi, regexprep} ## @end deftypefn -function y = regexptranslate (op, x) +function y = regexptranslate (op, s) if nargin != 2 print_usage (); @@ -60,11 +60,11 @@ if (ischar (op)) op = tolower (op); if (strcmp ("wildcard", op)) - y = regexprep (regexprep (regexprep (x, "\\.", "\\."), "\\*", + y = regexprep (regexprep (regexprep (s, "\\.", "\\."), "\\*", ".*"), "\\?", "."); elseif (strcmp ("escape", op)) ch = {'\$', '\.', '\?', '\[', '\]'}; - y = x; + y = s; for i = 1 : length (ch) y = regexprep (y, ch{i}, ch{i}); endfor diff --git a/scripts/strings/strjust.m b/scripts/strings/strjust.m --- a/scripts/strings/strjust.m +++ b/scripts/strings/strjust.m @@ -40,43 +40,43 @@ ## @seealso{deblank, strrep, strtrim, untabify} ## @end deftypefn -function y = strjust (x, just) +function y = strjust (s, pos) if (nargin < 1 || nargin > 2) print_usage (); endif if (nargin == 1) - just = "right"; + pos = "right"; else - just = tolower (just); + pos = tolower (pos); endif - if (ndims (x) != 2) + if (ndims (s) != 2) error ("strjust: input must be a string or character matrix"); endif - if (isempty (x)) - y = x; + if (isempty (s)) + y = s; else ## Apparently, Matlab considers nulls to be blanks as well; however, does ## not preserve the nulls, but rather converts them to blanks. That's a ## bit unexpected, but it allows simpler processing, because we can move ## just the nonblank characters. So we'll do the same here. - [nr, nc] = size (x); + [nr, nc] = size (s); ## Find the indices of all nonblanks. - nonbl = x != " " & x != "\0"; + nonbl = s != " " & s != "\0"; [idx, jdx] = find (nonbl); - if (strcmp (just, "right")) + if (strcmp (pos, "right")) ## We wish to find the maximum column index for each row. Because jdx is ## sorted, we can take advantage of the fact that assignment is processed ## sequentially and for duplicate indices the last value will remain. maxs = nc * ones (nr, 1); maxs(idx) = jdx; shift = nc - maxs; - elseif (strcmp (just, "left")) + elseif (strcmp (pos, "left")) ## See above for explanation. mins = ones (nr, 1); mins(flipud (idx(:))) = flipud (jdx(:)); @@ -95,7 +95,7 @@ ## Create a blank matrix and position the nonblank characters. y = " "(ones (1, nr), ones (1, nc)); - y(sub2ind ([nr, nc], idx, jdx)) = x(nonbl); + y(sub2ind ([nr, nc], idx, jdx)) = s(nonbl); endif endfunction diff --git a/scripts/strings/strmatch.m b/scripts/strings/strmatch.m --- a/scripts/strings/strmatch.m +++ b/scripts/strings/strmatch.m @@ -19,11 +19,11 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} strmatch (@var{s}, @var{a}, "exact") -## Return indices of entries of @var{a} that match the string @var{s}. -## The second argument @var{a} may be a string matrix or a cell array of +## @deftypefn {Function File} {} strmatch (@var{s}, @var{A}, "exact") +## Return indices of entries of @var{A} that match the string @var{s}. +## The second argument @var{A} may be a string matrix or a cell array of ## strings. If the third argument @code{"exact"} is not given, then -## @var{s} only needs to match @var{a} up to the length of @var{s}. +## @var{s} only needs to match @var{A} up to the length of @var{s}. ## Trailing whitespace is ignored. ## Results are returned as a column vector. ## For example: diff --git a/scripts/strings/untabify.m b/scripts/strings/untabify.m --- a/scripts/strings/untabify.m +++ b/scripts/strings/untabify.m @@ -50,7 +50,7 @@ ## Author: Ben Abbott ## Created: 2010-10-15 -function s = untabify (t, tw = 8, db = false) +function s = untabify (t, tw = 8, dblank = false) if (nargin > 0 && nargin < 4 && (ischar (t) || iscellstr (t))) if (ischar (t)) @@ -58,7 +58,7 @@ else s = cellfun (@(str) replace_tabs (str, tw), t, "uniformoutput", false); endif - if (db) + if (dblank) s = deblank (s); endif else diff --git a/scripts/time/asctime.m b/scripts/time/asctime.m --- a/scripts/time/asctime.m +++ b/scripts/time/asctime.m @@ -34,10 +34,10 @@ ## Author: jwe -function retval = asctime (t) +function retval = asctime (tm_struct) if (nargin == 1) - retval = strftime ("%a %b %d %H:%M:%S %Y\n", t); + retval = strftime ("%a %b %d %H:%M:%S %Y\n", tm_struct); else print_usage (); endif diff --git a/scripts/time/datenum.m b/scripts/time/datenum.m --- a/scripts/time/datenum.m +++ b/scripts/time/datenum.m @@ -65,65 +65,65 @@ ## Algorithm: Peter Baum (http://vsg.cape.com/~pbaum/date/date0.htm) ## Author: pkienzle -function [days, secs] = datenum (Y, M, D, h, m, s) +function [days, secs] = datenum (year, month, day, hour, minute, second) ## Days until start of month assuming year starts March 1. persistent monthstart = [306; 337; 0; 31; 61; 92; 122; 153; 184; 214; 245; 275]; - if (nargin == 0 || (nargin > 2 && ischar (Y)) || nargin > 6) + if (nargin == 0 || (nargin > 2 && ischar (year)) || nargin > 6) print_usage (); endif - if (ischar (Y)) + if (ischar (year)) if (nargin < 2) - M = []; + month = []; endif - [Y, M, D, h, m, s] = datevec (Y, M); + [year, month, day, hour, minute, second] = datevec (year, month); else - if (nargin < 6) s = 0; endif - if (nargin < 5) m = 0; endif - if (nargin < 4) h = 0; endif + if (nargin < 6) second = 0; endif + if (nargin < 5) minute = 0; endif + if (nargin < 4) hour = 0; endif if (nargin == 1) - nc = columns (Y); + nc = columns (year); if (nc > 6 || nc < 3) - error ("datenum: expected date vector containing [Y, M, D, h, m, s]"); + error ("datenum: expected date vector containing [year, month, day, hour, minute, second]"); endif - s = m = h = 0; - if (nc >= 6) s = Y(:,6); endif - if (nc >= 5) m = Y(:,5); endif - if (nc >= 4) h = Y(:,4); endif - D = Y(:,3); - M = Y(:,2); - Y = Y(:,1); + second = minute = hour = 0; + if (nc >= 6) second = year(:,6); endif + if (nc >= 5) minute = year(:,5); endif + if (nc >= 4) hour = year(:,4); endif + day = year(:,3); + month = year(:,2); + year = year(:,1); endif endif - M(M<1) = 1; ## For compatibility. Otherwise allow negative months. + month(month<1) = 1; ## For compatibility. Otherwise allow negative months. ## Set start of year to March by moving Jan. and Feb. to previous year. ## Correct for months > 12 by moving to subsequent years. - Y += fix ((M-14)/12); + year += fix ((month-14)/12); ## Lookup number of days since start of the current year. - if (numel (M) == 1 || numel (D) == 1) - ## Allow M or D to be scalar while other values may be vectors or + if (numel (month) == 1 || numel (day) == 1) + ## Allow month or day to be scalar while other values may be vectors or ## matrices. - D += monthstart (mod (M-1,12) + 1) + 60; - if (numel (M) > 1) - D = reshape (D, size (M)); + day += monthstart (mod (month-1,12) + 1) + 60; + if (numel (month) > 1) + day = reshape (day, size (month)); endif else - D += reshape (monthstart (mod (M-1,12) + 1), size (D)) + 60; + day += reshape (monthstart (mod (month-1,12) + 1), size (day)) + 60; endif ## Add number of days to the start of the current year. Correct ## for leap year every 4 years except centuries not divisible by 400. - D += 365*Y + floor (Y/4) - floor (Y/100) + floor (Y/400); + day += 365*year + floor (year/4) - floor (year/100) + floor (year/400); ## Add fraction representing current second of the day. - days = D + (h+(m+s/60)/60)/24; + days = day + (hour+(minute+second/60)/60)/24; ## Output seconds if asked so that etime can be more accurate - secs = 86400*D + h*3600 + m*60 + s; + secs = 86400*day + hour*3600 + minute*60 + second; endfunction diff --git a/scripts/time/datestr.m b/scripts/time/datestr.m --- a/scripts/time/datestr.m +++ b/scripts/time/datestr.m @@ -18,7 +18,9 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {@var{str} =} datestr (@var{date}, [@var{f}, [@var{p}]]) +## @deftypefn {Function File} {@var{str} =} datestr (@var{date}) +## @deftypefnx {Function File} {@var{str} =} datestr (@var{date}, @var{f}) +## @deftypefnx {Function File} {@var{str} =} datestr (@var{date}, @var{f}, @var{p}) ## Format the given date/time according to the format @code{f} and return ## the result in @var{str}. @var{date} is a serial date number (see ## @code{datenum}) or a date vector (see @code{datevec}). The value of diff --git a/scripts/time/etime.m b/scripts/time/etime.m --- a/scripts/time/etime.m +++ b/scripts/time/etime.m @@ -17,9 +17,9 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} etime (@var{t1}, @var{t2}) -## Return the difference (in seconds) between two time values returned from -## @code{clock}. For example: +## @deftypefn {Function File} {} etime (@var{t2}, @var{t1}) +## Return the difference in seconds between two time values returned from +## @code{clock} (@math{@var{t2} - @var{t1}}). For example: ## ## @example ## @group @@ -37,16 +37,16 @@ ## Author: jwe -function secs = etime (t1, t0) +function secs = etime (t2, t1) if (nargin != 2) print_usage (); endif - [d1, s1] = datenum (t1); - [d0, s0] = datenum (t0); + [~, s2] = datenum (t2); + [~, s1] = datenum (t1); - secs = s1 - s0; + secs = s2 - s1; endfunction diff --git a/scripts/time/weekday.m b/scripts/time/weekday.m --- a/scripts/time/weekday.m +++ b/scripts/time/weekday.m @@ -17,15 +17,16 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{n}, @var{s}] =} weekday (@var{d}, [@var{form}]) +## @deftypefn {Function File} {[@var{n}, @var{s}] =} weekday (@var{d}) +## @deftypefnx {Function File} {[@var{n}, @var{s}] =} weekday (@var{d}, @var{format}) ## Return the day of week as a number in @var{n} and a string in @var{s}, ## for example @code{[1, "Sun"]}, @code{[2, "Mon"]}, @dots{}, or ## @code{[7, "Sat"]}. ## ## @var{d} is a serial date number or a date string. ## -## If the string @var{form} is given and is @code{"long"}, @var{s} will -## contain the full name of the weekday; otherwise (or if @var{form} is +## If the string @var{format} is given and is @code{"long"}, @var{s} will +## contain the full name of the weekday; otherwise (or if @var{format} is ## @code{"short"}), @var{s} will contain the abbreviated name of the weekday. ## @seealso{datenum, datevec, eomday} ## @end deftypefn @@ -34,14 +35,14 @@ ## Created: 10 October 2001 (CVS) ## Adapted-By: William Poetra Yoga Hadisoeseno -function [d, s] = weekday (d, form) +function [d, s] = weekday (d, format) if (nargin < 1 || nargin > 2) print_usage (); endif if (nargin < 2) - form = "short"; + format = "short"; endif if (iscell (d) || isnumeric (d)) @@ -59,7 +60,7 @@ d(!d) = 7; if (nargout > 1) - if (strcmpi (form, "long")) + if (strcmpi (format, "long")) names = {"Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"}; else