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