1 ## Copyright (C) 1996, 2000, 2002, 2003, 2004, 2005, 2007
2 ## Auburn University. All rights reserved.
4 ## This program is free software: you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation, either version 3 of the License, or
7 ## (at your option) any later version.
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ## @deftypefn {Function File} {@var{bool} =} issample (@var{ts})
19 ## @deftypefnx {Function File} {@var{bool} =} issample (@var{ts}, @var{flg})
20 ## Return true if @var{ts} is a valid sampling time.
25 ## Alleged sampling time to be tested.
27 ## Accept real scalars @var{ts} > 0. Default Value.
29 ## Accept real scalars @var{ts} >= 0.
31 ## Accept real scalars @var{ts} > 0 and @var{ts} == -1.
33 ## Accept real scalars @var{ts} >= 0 and @var{ts} == -1.
35 ## Accept real scalars @var{ts} >= 0, @var{ts} == -1 and @var{ts} == -2.
41 ## True if conditions are met and false otherwise.
46 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu>
49 ## Adapted-By: Lukas Reichlin <lukas.reichlin@gmail.com>
50 ## Date: September 2009
53 function bool = issample (tsam, flg = 1)
55 if (nargin < 1 || nargin > 2)
61 bool = is_real_scalar (tsam) && (tsam > 0);
62 case 0 # continuous or discrete
63 bool = is_real_scalar (tsam) && (tsam >= 0);
64 case -1 # discrete, tsam unspecified
65 bool = is_real_scalar (tsam) && (tsam > 0 || tsam == -1);
66 case -10 # continuous or discrete, tsam unspecified
67 bool = is_real_scalar (tsam) && (tsam >= 0 || tsam == -1);
68 case -2 # accept static gains
69 bool = is_real_scalar (tsam) && (tsam >= 0 || tsam == -1 || tsam == -2);
78 %!assert (issample (1))
79 %!assert (issample (pi))
80 %!assert (issample (0), false)
81 %!assert (issample (-1), false)
82 %!assert (issample (-1, 1), false)
83 %!assert (issample ("a"), false)
84 %!assert (issample (eye (2)), false)
85 %!assert (issample (2+2i), false)
88 %!assert (issample (1, 0))
89 %!assert (issample (0, 0))
90 %!assert (issample (-1, 0), false)
91 %!assert (issample (pi, 0))
92 %!assert (issample ("b", 0), false)
93 %!assert (issample (rand (3,2), 0), false)
94 %!assert (issample (2+2i, 0), false)
95 %!assert (issample (0+2i, 0), false)
98 %!assert (issample (-1, -1))
99 %!assert (issample (0, -1), false)
100 %!assert (issample (1, -1))
101 %!assert (issample (pi, -1))
102 %!assert (issample (-pi, -1), false)
103 %!assert (issample ("b", -1), false)
104 %!assert (issample (rand (3,2), -1), false)
105 %!assert (issample (-2+2i, -1), false)
108 %!error (issample (-1, "ab"))
109 %!error (issample ())
110 %!error (issample (-1, -1, -1))
111 %!error (issample (1, pi))
112 %!error (issample (5, rand (2,3)))
113 %!error (issample (0, 1+2i))