Mercurial > hg > camir-aes2014
comparison core/tools/uimage.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function h = uimage(varargin) | |
2 %UIMAGE Display image with uneven axis. | |
3 % UIMAGE(X,Y,C) displays matrix C as an image, using the vectors X and | |
4 % Y to specify the X and Y coordinates. X and Y may be unevenly spaced | |
5 % vectors, but must be increasing. The size of C must be LENGTH(Y)* | |
6 % LENGTH(X). (Most probably you'll want to display C' instead of C). | |
7 % | |
8 % Contrary to Matlab's original IMAGE function, here the vectors X and Y | |
9 % do not need to be linearly spaced. Whereas IMAGE linearly interpolates | |
10 % the X-axis between X(1) and X(end), ignoring all other values (idem | |
11 % for Y), UIMAGE allows for X and/or Y to be unevenly spaced vectors, by | |
12 % locally stretching the matrix C (ie, by duplicating some elements of C) | |
13 % for larger X and/or Y intervals. | |
14 % | |
15 % The syntax for UIMAGE(X,Y,C,...) is the same as IMAGE(X,Y,C,...) | |
16 % (all the remaining arguments, eg 'PropertyName'-PropertyValue pairs, | |
17 % are passed to IMAGE). See IMAGE for details. | |
18 % | |
19 % Use UIMAGESC to scale the data using the full colormap. The syntax for | |
20 % UIMAGESC(X,Y,C,...) is the same as IMAGESC(X,Y,C,...). | |
21 % | |
22 % Typical uses: | |
23 % - Plotting a spatio-temporal diagram (T,X), with unevenly spaced | |
24 % time intervals for T (eg, when some values are missing, or when | |
25 % using a non-constant sampling rate). | |
26 % - Plotting a set of power spectra with frequency in log-scale. | |
27 % | |
28 % h = UIMAGE(X,Y,C,...) returns a handle to the image. | |
29 % | |
30 % Example: | |
31 % c = randn(50,20); % Random 50x20 matrix | |
32 % x = logspace(1,3,50); % log-spaced X-axis, between 10 and 1000 | |
33 % y = linspace(3,8,20); % lin-spaced Y-axis, between 3 and 8 | |
34 % uimagesc(x,y,c'); % displays the matrix | |
35 % | |
36 % F. Moisy | |
37 % Revision: 1.03, Date: 2006/06/14. | |
38 % | |
39 % See also IMAGE, IMAGESC, UIMAGESC. | |
40 | |
41 | |
42 % History: | |
43 % 2006/06/12: v1.00, first version. | |
44 % 2006/06/14: v1.03, minor bug fixed; works in ML6. | |
45 | |
46 error(nargchk(3,inf,nargin)); | |
47 | |
48 % maximum number of matrix elements to interpolate the uneven axis | |
49 % (typically between 500 and 5000): | |
50 nmax = 2000; | |
51 | |
52 x = varargin{1}; | |
53 y = varargin{2}; | |
54 c = varargin{3}; | |
55 | |
56 if any(diff(x)<=0) || any(diff(y)<=0) | |
57 error('The X and Y axis should be increasing.'); | |
58 end | |
59 | |
60 dx = min(diff(x)); % smallest interval for X | |
61 dy = min(diff(y)); % smallest interval for Y | |
62 | |
63 % test if X and Y are linearly spaced (to within 10^-12): | |
64 evenx = all(abs(diff(x)/dx-1)<1e-12); % true if X is linearly spaced | |
65 eveny = all(abs(diff(y)/dy-1)<1e-12); % true if Y is linearly spaced | |
66 | |
67 | |
68 if evenx && eveny % X and Y both evenly spaced | |
69 | |
70 xe = x; | |
71 ye = y; | |
72 ce = c; | |
73 | |
74 elseif evenx && ~eveny % X even and Y uneven | |
75 | |
76 nx = length(x); | |
77 xe = x; | |
78 | |
79 ny = ceil(1 + (y(end) - y(1))/dy); % number of points for Y | |
80 ny = min(ny, nmax); | |
81 ye = linspace(y(1), y(end), ny); | |
82 | |
83 ce = zeros(ny,nx); | |
84 | |
85 for j=1:ny | |
86 indj = find(y<=ye(j)); | |
87 ce(j,1:nx) = c(indj(end), 1:nx); | |
88 end; | |
89 | |
90 elseif ~evenx && eveny % X uneven and Y even | |
91 | |
92 nx = ceil(1 + (x(end) - x(1))/dx); % number of points for X | |
93 nx = min(nx, nmax); | |
94 xe = linspace(x(1), x(end), nx); | |
95 | |
96 ny = length(y); | |
97 ye = y; | |
98 | |
99 ce = zeros(ny,nx); | |
100 | |
101 for i=1:nx | |
102 indi = find(x<=xe(i)); | |
103 ce(1:ny,i) = c(1:ny, indi(end)); | |
104 end; | |
105 | |
106 elseif ~evenx && ~eveny % X and Y both uneven | |
107 | |
108 nx = ceil(1 + (x(end) - x(1))/dx); % number of points for X | |
109 nx = min(nx, nmax); | |
110 xe = linspace(x(1), x(end), nx); | |
111 | |
112 ny = ceil(1 + (y(end) - y(1))/dy); % number of points for Y | |
113 ny = min(ny, nmax); | |
114 ye = linspace(y(1), y(end), ny); | |
115 | |
116 ce = zeros(ny,nx); | |
117 | |
118 for i=1:nx | |
119 for j=1:ny | |
120 indi = find(x<=xe(i)); | |
121 indj = find(y<=ye(j)); | |
122 ce(j,i) = c(indi(end), indj(end)); | |
123 end; | |
124 end; | |
125 | |
126 end | |
127 | |
128 hh = image(xe, ye, ce, varargin{4:end}); | |
129 | |
130 if nargout>0 | |
131 h = hh; | |
132 end |