]> Creatis software - CreaPhase.git/blob - octave_packages/nnet-0.1.13/min_max.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nnet-0.1.13 / min_max.m
1 ## Copyright (C) 2005 Michel D. Schmid  <michaelschmid@users.sourceforge.net>
2 ##
3 ##
4 ## This program is free software; you can redistribute it and/or modify it
5 ## under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 2, or (at your option)
7 ## any later version.
8 ##
9 ## This program is distributed in the hope that it will be useful, but
10 ## WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 ## General Public License for more details.
13 ##
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; see the file COPYING.  If not, see
16 ## <http://www.gnu.org/licenses/>.
17
18 ## -*- texinfo -*-
19 ## @deftypefn {Function File} {} @var{Pr} = min_max (@var{Pp})
20 ## @code{min_max} returns variable Pr with range of matrix rows
21 ##
22 ## @example
23 ## PR - R x 2 matrix of min and max values for R input elements
24 ## @end example
25 ##
26 ## @example
27 ## Pp = [1 2 3; -1 -0.5 -3]
28 ## pr = min_max(Pp);
29 ## pr = [1 3; -0.5 -3];
30 ## @end example
31 ## @end deftypefn
32
33 ## Author: Michel D. Schmid
34
35 function Pr = min_max(Pp)
36
37   ## check number of input args
38   error(nargchk(1,1,nargin))
39
40   Pr = []; # returns an empty matrix
41   #if ismatrix(Pp)
42   if (!(size(Pp,1)==1) && !(size(Pp,2)==1)) # ismatrix(1) will return 1!!!
43     if isreal(Pp) # be sure, this is no complex matrix
44       Pr = [min(Pp,[],2) max(Pp,[],2)];
45     else
46       error("Argument has illegal type.")
47     endif
48   else
49     error("Argument must be a matrix.")
50   endif
51
52 endfunction
53
54 %!shared
55 %! disp("testing min_max")
56 %!test fail("min_max(1)","Argument must be a matrix.")
57 %!test fail("min_max('testString')","Argument must be a matrix.")
58 %!test fail("min_max(cellA{1}=1)","Argument must be a matrix.")
59 %!test fail("min_max([1+1i, 2+2i])","Argument must be a matrix.")
60 %!test fail("min_max([1+1i, 2+2i; 3+1i, 4+2i])","Argument has illegal type.")
61
62