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