Mercurial > hg > octave-lyh
changeset 9867:1c274aa2b4d1
make issquare consistent for empty matrices
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 24 Nov 2009 14:12:02 +0100 |
parents | b5aa5d9ee6b9 |
children | 7f4939e76684 |
files | scripts/ChangeLog scripts/general/issquare.m |
diffstat | 2 files changed, 14 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2009-11-24 Jaroslav Hajek <highegg@gmail.com> + + * general/issquare.m: Change to return consistent result for empty + matrices. + 2009-11-24 Jaroslav Hajek <highegg@gmail.com> * general/cell2mat.m: Check type of all elements. Slightly optimize.
--- a/scripts/general/issquare.m +++ b/scripts/general/issquare.m @@ -18,8 +18,8 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} issquare (@var{x}) -## If @var{x} is a square matrix, then return the dimension of @var{x}. -## Otherwise, return 0. +## If @var{x} is a square matrix, return true. +## Otherwise, return false. ## @seealso{size, rows, columns, length, ismatrix, isscalar, isvector} ## @end deftypefn @@ -29,14 +29,12 @@ function retval = issquare (x) - retval = 0; - if (nargin == 1) - if (ismatrix (x) && ndims (x) < 3) - [nr, nc] = size (x); - if (nr == nc && nr > 0) - retval = nr; - endif + if (ismatrix (x) && ndims (x) == 2) + [r, c] = size (x); + retval = r == c; + else + retval = false; endif else print_usage (); @@ -48,18 +46,16 @@ %!assert(!(issquare ([1, 2]))); -%!assert(!(issquare ([]))); +%!assert(issquare ([])); -%!assert(issquare ([1, 2; 3, 4]) == 2); +%!assert(issquare ([1, 2; 3, 4])); %!test -%! warn_str_to_num = 0; %! assert(!(issquare ("t"))); %!assert(!(issquare ("test"))); %!test -%! warn_str_to_num = 0; %! assert(!(issquare (["test"; "ing"; "1"; "2"]))); %!test