annotate _misc/figures/.svn/text-base/uimage.m.svn-base @ 9:4ea6619cb3f5 tip

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