Daniel@0: function h = uimage(varargin) Daniel@0: %UIMAGE Display image with uneven axis. Daniel@0: % UIMAGE(X,Y,C) displays matrix C as an image, using the vectors X and Daniel@0: % Y to specify the X and Y coordinates. X and Y may be unevenly spaced Daniel@0: % vectors, but must be increasing. The size of C must be LENGTH(Y)* Daniel@0: % LENGTH(X). (Most probably you'll want to display C' instead of C). Daniel@0: % Daniel@0: % Contrary to Matlab's original IMAGE function, here the vectors X and Y Daniel@0: % do not need to be linearly spaced. Whereas IMAGE linearly interpolates Daniel@0: % the X-axis between X(1) and X(end), ignoring all other values (idem Daniel@0: % for Y), UIMAGE allows for X and/or Y to be unevenly spaced vectors, by Daniel@0: % locally stretching the matrix C (ie, by duplicating some elements of C) Daniel@0: % for larger X and/or Y intervals. Daniel@0: % Daniel@0: % The syntax for UIMAGE(X,Y,C,...) is the same as IMAGE(X,Y,C,...) Daniel@0: % (all the remaining arguments, eg 'PropertyName'-PropertyValue pairs, Daniel@0: % are passed to IMAGE). See IMAGE for details. Daniel@0: % Daniel@0: % Use UIMAGESC to scale the data using the full colormap. The syntax for Daniel@0: % UIMAGESC(X,Y,C,...) is the same as IMAGESC(X,Y,C,...). Daniel@0: % Daniel@0: % Typical uses: Daniel@0: % - Plotting a spatio-temporal diagram (T,X), with unevenly spaced Daniel@0: % time intervals for T (eg, when some values are missing, or when Daniel@0: % using a non-constant sampling rate). Daniel@0: % - Plotting a set of power spectra with frequency in log-scale. Daniel@0: % Daniel@0: % h = UIMAGE(X,Y,C,...) returns a handle to the image. Daniel@0: % Daniel@0: % Example: Daniel@0: % c = randn(50,20); % Random 50x20 matrix Daniel@0: % x = logspace(1,3,50); % log-spaced X-axis, between 10 and 1000 Daniel@0: % y = linspace(3,8,20); % lin-spaced Y-axis, between 3 and 8 Daniel@0: % uimagesc(x,y,c'); % displays the matrix Daniel@0: % Daniel@0: % F. Moisy Daniel@0: % Revision: 1.03, Date: 2006/06/14. Daniel@0: % Daniel@0: % See also IMAGE, IMAGESC, UIMAGESC. Daniel@0: Daniel@0: Daniel@0: % History: Daniel@0: % 2006/06/12: v1.00, first version. Daniel@0: % 2006/06/14: v1.03, minor bug fixed; works in ML6. Daniel@0: Daniel@0: error(nargchk(3,inf,nargin)); Daniel@0: Daniel@0: % maximum number of matrix elements to interpolate the uneven axis Daniel@0: % (typically between 500 and 5000): Daniel@0: nmax = 2000; Daniel@0: Daniel@0: x = varargin{1}; Daniel@0: y = varargin{2}; Daniel@0: c = varargin{3}; Daniel@0: Daniel@0: if any(diff(x)<=0) || any(diff(y)<=0) Daniel@0: error('The X and Y axis should be increasing.'); Daniel@0: end Daniel@0: Daniel@0: dx = min(diff(x)); % smallest interval for X Daniel@0: dy = min(diff(y)); % smallest interval for Y Daniel@0: Daniel@0: % test if X and Y are linearly spaced (to within 10^-12): Daniel@0: evenx = all(abs(diff(x)/dx-1)<1e-12); % true if X is linearly spaced Daniel@0: eveny = all(abs(diff(y)/dy-1)<1e-12); % true if Y is linearly spaced Daniel@0: Daniel@0: Daniel@0: if evenx && eveny % X and Y both evenly spaced Daniel@0: Daniel@0: xe = x; Daniel@0: ye = y; Daniel@0: ce = c; Daniel@0: Daniel@0: elseif evenx && ~eveny % X even and Y uneven Daniel@0: Daniel@0: nx = length(x); Daniel@0: xe = x; Daniel@0: Daniel@0: ny = ceil(1 + (y(end) - y(1))/dy); % number of points for Y Daniel@0: ny = min(ny, nmax); Daniel@0: ye = linspace(y(1), y(end), ny); Daniel@0: Daniel@0: ce = zeros(ny,nx); Daniel@0: Daniel@0: for j=1:ny Daniel@0: indj = find(y<=ye(j)); Daniel@0: ce(j,1:nx) = c(indj(end), 1:nx); Daniel@0: end; Daniel@0: Daniel@0: elseif ~evenx && eveny % X uneven and Y even Daniel@0: Daniel@0: nx = ceil(1 + (x(end) - x(1))/dx); % number of points for X Daniel@0: nx = min(nx, nmax); Daniel@0: xe = linspace(x(1), x(end), nx); Daniel@0: Daniel@0: ny = length(y); Daniel@0: ye = y; Daniel@0: Daniel@0: ce = zeros(ny,nx); Daniel@0: Daniel@0: for i=1:nx Daniel@0: indi = find(x<=xe(i)); Daniel@0: ce(1:ny,i) = c(1:ny, indi(end)); Daniel@0: end; Daniel@0: Daniel@0: elseif ~evenx && ~eveny % X and Y both uneven Daniel@0: Daniel@0: nx = ceil(1 + (x(end) - x(1))/dx); % number of points for X Daniel@0: nx = min(nx, nmax); Daniel@0: xe = linspace(x(1), x(end), nx); Daniel@0: Daniel@0: ny = ceil(1 + (y(end) - y(1))/dy); % number of points for Y Daniel@0: ny = min(ny, nmax); Daniel@0: ye = linspace(y(1), y(end), ny); Daniel@0: Daniel@0: ce = zeros(ny,nx); Daniel@0: Daniel@0: for i=1:nx Daniel@0: for j=1:ny Daniel@0: indi = find(x<=xe(i)); Daniel@0: indj = find(y<=ye(j)); Daniel@0: ce(j,i) = c(indi(end), indj(end)); Daniel@0: end; Daniel@0: end; Daniel@0: Daniel@0: end Daniel@0: Daniel@0: hh = image(xe, ye, ce, varargin{4:end}); Daniel@0: Daniel@0: if nargout>0 Daniel@0: h = hh; Daniel@0: end