8920
|
1 ## Copyright (C) 1996, 1997, 2002, 2004, 2005, 2006, 2007, 2008 John W. Eaton |
4026
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
4026
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
4026
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} issquare (@var{x}) |
|
21 ## If @var{x} is a square matrix, then return the dimension of @var{x}. |
|
22 ## Otherwise, return 0. |
5642
|
23 ## @seealso{size, rows, columns, length, ismatrix, isscalar, isvector} |
4026
|
24 ## @end deftypefn |
|
25 |
|
26 ## Author: A. S. Hodel <scotte@eng.auburn.edu> |
|
27 ## Created: August 1993 |
|
28 ## Adapted-By: jwe |
|
29 |
|
30 function retval = issquare (x) |
|
31 |
|
32 retval = 0; |
|
33 |
|
34 if (nargin == 1) |
4890
|
35 if (ismatrix (x) && ndims (x) < 3) |
4026
|
36 [nr, nc] = size (x); |
|
37 if (nr == nc && nr > 0) |
|
38 retval = nr; |
|
39 endif |
|
40 endif |
|
41 else |
6046
|
42 print_usage (); |
4026
|
43 endif |
|
44 |
|
45 endfunction |
7411
|
46 |
|
47 %!assert(issquare (1)); |
|
48 |
|
49 %!assert(!(issquare ([1, 2]))); |
|
50 |
|
51 %!assert(!(issquare ([]))); |
|
52 |
|
53 %!assert(issquare ([1, 2; 3, 4]) == 2); |
|
54 |
|
55 %!test |
|
56 %! warn_str_to_num = 0; |
|
57 %! assert(!(issquare ("t"))); |
|
58 |
|
59 %!assert(!(issquare ("test"))); |
|
60 |
|
61 %!test |
|
62 %! warn_str_to_num = 0; |
|
63 %! assert(!(issquare (["test"; "ing"; "1"; "2"]))); |
|
64 |
|
65 %!test |
|
66 %! s.a = 1; |
|
67 %! assert(!(issquare (s))); |
|
68 |
|
69 %!assert(!(issquare ([1, 2; 3, 4; 5, 6]))); |
|
70 |
|
71 %!error issquare (); |
|
72 |
|
73 %!error issquare ([1, 2; 3, 4], 2); |
|
74 |