2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
1024
|
19 |
2311
|
20 ## Scale and display a matrix as an image. |
|
21 ## |
|
22 ## imagesc(x) displays a scaled version of the matrix x. The matrix is |
|
23 ## scaled so that its entries are indices into the current colormap. |
|
24 ## The scaled matrix is returned. |
|
25 ## |
|
26 ## imagesc (x, zoom) sets the magnification, the default value is 4. |
|
27 ## |
|
28 ## SEE ALSO: image, imshow |
559
|
29 |
3202
|
30 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
31 ## Created: July 1994 |
|
32 ## Adapted-By: jwe |
904
|
33 |
2312
|
34 function x = imagesc (x, zoom) |
559
|
35 |
|
36 if (nargin < 1 || nargin > 2) |
904
|
37 usage ("image (matrix, [zoom])"); |
1024
|
38 elseif (nargin == 1) |
559
|
39 zoom = 4; |
|
40 endif |
|
41 |
1024
|
42 [ high, wide ] = size (x); |
559
|
43 |
1024
|
44 maxval = max (max (x)); |
|
45 minval = min (min (x)); |
559
|
46 |
2303
|
47 ## Rescale matrix so that all values are in the range 0 to |
|
48 ## length (colormap) inclusive. |
1024
|
49 |
559
|
50 if (maxval == minval) |
1024
|
51 x = ones (high, wide); |
559
|
52 else |
2303
|
53 ## Rescale values to between 1 and length (colormap) inclusive. |
1024
|
54 x = fix ((x - minval) / (maxval - minval) * (length (colormap) - 1)) + 1; |
559
|
55 endif |
|
56 |
1024
|
57 image (x, zoom); |
559
|
58 |
|
59 endfunction |