Mercurial > hg > octave-lojdl
changeset 12488:bea828c03969
Add new isrow, iscolumn functions.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 28 Feb 2011 22:35:41 -0800 |
parents | bac54daffde2 |
children | ac3bdc27734e |
files | ChangeLog NEWS doc/ChangeLog doc/interpreter/numbers.txi scripts/ChangeLog scripts/general/iscolumn.m scripts/general/isrow.m scripts/general/module.mk |
diffstat | 8 files changed, 149 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-02-28 Rik <octave@nomad.inbox5.com> + + * NEWS: Mention new functions isrow, iscolumn. + 2011-02-23 Jordi GutiƩrrez Hermoso <jordigh@gmail.com> * .hgignore: Cleanup and more files to be ignore that get added
--- a/NEWS +++ b/NEWS @@ -1,6 +1,12 @@ Summary of important user-visible changes for version 3.6: --------------------------------------------------------- + ** The PCRE library is now required to build Octave. + + ** New functions added. + iscolumn + issrow + ** Deprecated functions. The following functions were deprecated in Octave 3.2 and have been @@ -18,8 +24,6 @@ spchol splchol unmark_command spchol2inv split unmark_rawcommand - ** The PCRE library is now required to build Octave. - Summary of important user-visible changes for version 3.4: ---------------------------------------------------------
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2010-02-28 Rik <octave@nomad.inbox5.com> + + * interpreter/numbers.txi: Add isrow, iscolumn functions to manual. + 2011-02-25 Jordi GutiƩrrez Hermoso <jordigh@gmail.com> * faq/OctaveFAQ.texi: Uniformise all mentions of Matlab to be
--- a/doc/interpreter/numbers.txi +++ b/doc/interpreter/numbers.txi @@ -819,6 +819,10 @@ @DOCSTRING(isvector) +@DOCSTRING(isrow) + +@DOCSTRING(iscolumn) + @DOCSTRING(isscalar) @DOCSTRING(issquare)
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2010-02-28 Rik <octave@nomad.inbox5.com> + + * general/iscolumn.m, general/isrow.m: Add 2 new utility functions + to check for row or column vector. + 2010-02-28 Rik <octave@nomad.inbox5.com> * sparse/treeplot.m: Use 'o' plot style as default for nodes
new file mode 100644 --- /dev/null +++ b/scripts/general/iscolumn.m @@ -0,0 +1,62 @@ +## Copyright (C) 2011 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} iscolumn (@var{x}) +## Return true if @var{x} is a column vector. +## @seealso{isrow, isscalar, isvector, ismatrix} +## @end deftypefn + +## Author: Rik Wehbring + +function retval = iscolumn (x) + + retval = false; + + if (nargin != 1) + print_usage (); + endif + + sz = size (x); + retval = (ndims (x) == 2 && (sz(2) == 1)); + +endfunction + +%!assert(iscolumn ([1, 2, 3]), false); +%!assert(iscolumn ([1; 2; 3])); +%!assert(iscolumn (1)); +%!assert(iscolumn ([]), false); +%!assert(iscolumn ([1, 2; 3, 4]), false); + +%!test +%! warning ("off", "Octave:str-to-num"); +%! assert((iscolumn ("t"))); +%!test +%! warning ("off", "Octave:str-to-num"); +%! assert(!(iscolumn ("test"))); + +%!assert(!(iscolumn (["test"; "ing"]))); + +%!test +%! s.a = 1; +%! assert((iscolumn (s))); + +%% Test input validation +%!error iscolumn (); +%!error iscolumn ([1, 2], 2); +
new file mode 100644 --- /dev/null +++ b/scripts/general/isrow.m @@ -0,0 +1,62 @@ +## Copyright (C) 2011 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} isrow (@var{x}) +## Return true if @var{x} is a row vector. +## @seealso{iscolumn, isscalar, isvector, ismatrix} +## @end deftypefn + +## Author: Rik Wehbring + +function retval = isrow (x) + + retval = false; + + if (nargin != 1) + print_usage (); + endif + + sz = size (x); + retval = (ndims (x) == 2 && (sz(1) == 1)); + +endfunction + +%!assert(isrow ([1, 2, 3])); +%!assert(isrow ([1; 2; 3]), false); +%!assert(isrow (1)); +%!assert(isrow ([]), false); +%!assert(isrow ([1, 2; 3, 4]), false); + +%!test +%! warning ("off", "Octave:str-to-num"); +%! assert((isrow ("t"))); +%!test +%! warning ("off", "Octave:str-to-num"); +%! assert((isrow ("test"))); + +%!assert(!(isrow (["test"; "ing"]))); + +%!test +%! s.a = 1; +%! assert((isrow (s))); + +%% Test input validation +%!error isrow (); +%!error isrow ([1, 2], 2); +
--- a/scripts/general/module.mk +++ b/scripts/general/module.mk @@ -44,9 +44,11 @@ general/interpft.m \ general/is_duplicate_entry.m \ general/isa.m \ + general/iscolumn.m \ general/isdir.m \ general/isequal.m \ general/isequalwithequalnans.m \ + general/isrow.m \ general/isscalar.m \ general/issquare.m \ general/isvector.m \