annotate core/tools/uimage.m @ 0:cc4b1211e677 tip

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