Mercurial > hg > octave-terminal
changeset 3197:a998db745232
[project @ 1998-10-29 00:26:52 by jwe]
author | jwe |
---|---|
date | Thu, 29 Oct 1998 00:26:52 +0000 |
parents | 3ac3e8edc258 |
children | 832e48821234 |
files | scripts/general/is_matrix.m scripts/general/is_scalar.m scripts/general/is_square.m scripts/general/is_symmetric.m scripts/general/is_vector.m scripts/general/isempty.m |
diffstat | 6 files changed, 36 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
deleted file mode 100644 --- a/scripts/general/is_matrix.m +++ /dev/null @@ -1,37 +0,0 @@ -## Copyright (C) 1996, 1997 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 2, 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, write to the Free -## Software Foundation, 59 Temple Place - Suite 330, Boston, MA -## 02111-1307, USA. - -## usage: is_matrix (x) -## -## Return 1 if X is a matrix. Otherwise, return 0. -## -## See also: size, rows, columns, length, is_scalar, is_vector - -## Author: jwe - -function retval = is_matrix (x) - - if (nargin == 1) - [nr, nc] = size (x); - retval = (nr > 0 && nc > 0); - else - usage ("is_matrix (x)"); - endif - -endfunction
--- a/scripts/general/is_scalar.m +++ b/scripts/general/is_scalar.m @@ -27,9 +27,13 @@ function retval = is_scalar (x) + retval = 0; + if (nargin == 1) - [nr, nc] = size (x); - retval = (nr == 1 && nc == 1); + if (is_matrix (x)) + [nr, nc] = size (x); + retval = (nr == 1 && nc == 1); + endif else usage ("is_scalar (x)"); endif
--- a/scripts/general/is_square.m +++ b/scripts/general/is_square.m @@ -30,12 +30,14 @@ function retval = is_square (x) + retval = 0; + if (nargin == 1) - [nr, nc] = size (x); - if (nr == nc && nr > 0) - retval = nr; - else - retval = 0; + if (is_matrix (x)) + [nr, nc] = size (x); + if (nr == nc && nr > 0) + retval = nr; + endif endif else usage ("is_square (x)");
--- a/scripts/general/is_symmetric.m +++ b/scripts/general/is_symmetric.m @@ -33,16 +33,15 @@ retval = 0; if (nargin == 1 || nargin == 2) - [nr, nc] = size (x); - if (nr == nc && nr > 0) - if (nargin == 1) - tol = eps; - endif - if (isstr (x)) - x = toascii (x); - endif - if (norm (x - x') / norm(x) <= tol) - retval = nr; + if (is_matrix (x)) + [nr, nc] = size (x); + if (nr == nc && nr > 0) + if (nargin == 1) + tol = eps; + endif + if (norm (x - x') / norm(x) <= tol) + retval = nr; + endif endif endif else
--- a/scripts/general/is_vector.m +++ b/scripts/general/is_vector.m @@ -27,9 +27,13 @@ function retval = is_vector (x) + retval = 0; + if (nargin == 1) - [nr, nc] = size (x); - retval = ((nr == 1 && nc >= 1) || (nc == 1 && nr >= 1)); + if (is_matrix (x)) + [nr, nc] = size (x); + retval = ((nr == 1 && nc >= 1) || (nc == 1 && nr >= 1)); + endif else usage ("is_vector (x)"); endif
--- a/scripts/general/isempty.m +++ b/scripts/general/isempty.m @@ -25,12 +25,16 @@ function retval = isempty (var) - if (nargin != 1) + retval = 0; + + if (nargin == 1) + if (is_matrix (var)) + [nr, nc] = size (var); + retval = (nr == 0 || nc == 0); + endif + else usage ("isempty (var)"); endif - [nr, nc] = size (var); - - retval = (nr == 0 || nc == 0); endfunction