UIMAGE Display image with uneven axis. UIMAGE(X,Y,C) displays matrix C as an image, using the vectors X and Y to specify the X and Y coordinates. X and Y may be unevenly spaced vectors, but must be increasing. The size of C must be LENGTH(Y)* LENGTH(X). (Most probably you'll want to display C' instead of C). Contrary to Matlab's original IMAGE function, here the vectors X and Y do not need to be linearly spaced. Whereas IMAGE linearly interpolates the X-axis between X(1) and X(end), ignoring all other values (idem for Y), UIMAGE allows for X and/or Y to be unevenly spaced vectors, by locally stretching the matrix C (ie, by duplicating some elements of C) for larger X and/or Y intervals. The syntax for UIMAGE(X,Y,C,...) is the same as IMAGE(X,Y,C,...) (all the remaining arguments, eg 'PropertyName'-PropertyValue pairs, are passed to IMAGE). See IMAGE for details. Use UIMAGESC to scale the data using the full colormap. The syntax for UIMAGESC(X,Y,C,...) is the same as IMAGESC(X,Y,C,...). Typical uses: - Plotting a spatio-temporal diagram (T,X), with unevenly spaced time intervals for T (eg, when some values are missing, or when using a non-constant sampling rate). - Plotting a set of power spectra with frequency in log-scale. h = UIMAGE(X,Y,C,...) returns a handle to the image. Example: c = randn(50,20); % Random 50x20 matrix x = logspace(1,3,50); % log-spaced X-axis, between 10 and 1000 y = linspace(3,8,20); % lin-spaced Y-axis, between 3 and 8 uimagesc(x,y,c'); % displays the matrix F. Moisy Revision: 1.03, Date: 2006/06/14. See also IMAGE, IMAGESC, UIMAGESC.
0001 function h = uimage(varargin) 0002 %UIMAGE Display image with uneven axis. 0003 % UIMAGE(X,Y,C) displays matrix C as an image, using the vectors X and 0004 % Y to specify the X and Y coordinates. X and Y may be unevenly spaced 0005 % vectors, but must be increasing. The size of C must be LENGTH(Y)* 0006 % LENGTH(X). (Most probably you'll want to display C' instead of C). 0007 % 0008 % Contrary to Matlab's original IMAGE function, here the vectors X and Y 0009 % do not need to be linearly spaced. Whereas IMAGE linearly interpolates 0010 % the X-axis between X(1) and X(end), ignoring all other values (idem 0011 % for Y), UIMAGE allows for X and/or Y to be unevenly spaced vectors, by 0012 % locally stretching the matrix C (ie, by duplicating some elements of C) 0013 % for larger X and/or Y intervals. 0014 % 0015 % The syntax for UIMAGE(X,Y,C,...) is the same as IMAGE(X,Y,C,...) 0016 % (all the remaining arguments, eg 'PropertyName'-PropertyValue pairs, 0017 % are passed to IMAGE). See IMAGE for details. 0018 % 0019 % Use UIMAGESC to scale the data using the full colormap. The syntax for 0020 % UIMAGESC(X,Y,C,...) is the same as IMAGESC(X,Y,C,...). 0021 % 0022 % Typical uses: 0023 % - Plotting a spatio-temporal diagram (T,X), with unevenly spaced 0024 % time intervals for T (eg, when some values are missing, or when 0025 % using a non-constant sampling rate). 0026 % - Plotting a set of power spectra with frequency in log-scale. 0027 % 0028 % h = UIMAGE(X,Y,C,...) returns a handle to the image. 0029 % 0030 % Example: 0031 % c = randn(50,20); % Random 50x20 matrix 0032 % x = logspace(1,3,50); % log-spaced X-axis, between 10 and 1000 0033 % y = linspace(3,8,20); % lin-spaced Y-axis, between 3 and 8 0034 % uimagesc(x,y,c'); % displays the matrix 0035 % 0036 % F. Moisy 0037 % Revision: 1.03, Date: 2006/06/14. 0038 % 0039 % See also IMAGE, IMAGESC, UIMAGESC. 0040 0041 0042 % History: 0043 % 2006/06/12: v1.00, first version. 0044 % 2006/06/14: v1.03, minor bug fixed; works in ML6. 0045 % 2006/12/14 - Petr Janata modified algorithm for determining if dimension is evenly spaced 0046 0047 error(nargchk(3,inf,nargin)); 0048 0049 % maximum number of matrix elements to interpolate the uneven axis 0050 % (typically between 500 and 5000): 0051 nmax = 2000; 0052 0053 x = varargin{1}; 0054 y = varargin{2}; 0055 c = varargin{3}; 0056 0057 if any(diff(x)<=0) || any(diff(y)<=0) 0058 error('The X and Y axis should be increasing.'); 0059 end 0060 0061 dx = min(diff(x)); % smallest interval for X 0062 dy = min(diff(y)); % smallest interval for Y 0063 0064 % test if X and Y are linearly spaced (to within 10^-12): 0065 evenx = all(abs(diff(x)/dx-1)<1e-12); % true if X is linearly spaced 0066 evenx = all(abs(diff(diff(x)))<1e-12); % PJ 0067 eveny = all(abs(diff(y)/dy-1)<1e-12); % true if Y is linearly spaced 0068 eveny = all(abs(diff(diff(y)))<1e-12); % PJ 0069 0070 0071 if evenx && eveny % X and Y both evenly spaced 0072 0073 xe = x; 0074 ye = y; 0075 ce = c; 0076 0077 elseif evenx && ~eveny % X even and Y uneven 0078 0079 nx = length(x); 0080 xe = x; 0081 0082 ny = ceil(1 + (y(end) - y(1))/dy); % number of points for Y 0083 ny = min(ny, nmax); 0084 ye = linspace(y(1), y(end), ny); 0085 0086 ce = zeros(ny,nx); 0087 0088 for j=1:ny 0089 indj = find(y<=ye(j)); 0090 ce(j,1:nx) = c(indj(end), 1:nx); 0091 end; 0092 0093 elseif ~evenx && eveny % X uneven and Y even 0094 0095 nx = ceil(1 + (x(end) - x(1))/dx); % number of points for X 0096 nx = min(nx, nmax); 0097 xe = linspace(x(1), x(end), nx); 0098 0099 ny = length(y); 0100 ye = y; 0101 0102 ce = zeros(ny,nx); 0103 0104 for i=1:nx 0105 indi = find(x<=xe(i)); 0106 ce(1:ny,i) = c(1:ny, indi(end)); 0107 end; 0108 0109 elseif ~evenx && ~eveny % X and Y both uneven 0110 0111 nx = ceil(1 + (x(end) - x(1))/dx); % number of points for X 0112 nx = min(nx, nmax); 0113 xe = linspace(x(1), x(end), nx); 0114 0115 ny = ceil(1 + (y(end) - y(1))/dy); % number of points for Y 0116 ny = min(ny, nmax); 0117 ye = linspace(y(1), y(end), ny); 0118 0119 ce = zeros(ny,nx); 0120 0121 for i=1:nx 0122 for j=1:ny 0123 indi = find(x<=xe(i)); 0124 indj = find(y<=ye(j)); 0125 ce(j,i) = c(indi(end), indj(end)); 0126 end; 0127 end; 0128 0129 end 0130 0131 hh = image(xe, ye, ce, varargin{4:end}); 0132 0133 if nargout>0 0134 h = hh; 0135 end