v_imagescnu

PURPOSE ^

Plot image with non-uniform rectangular patches

SYNOPSIS ^

function v_imagescnu(x,y,v,db)

DESCRIPTION ^

 Plot image with non-uniform rectangular patches

  Usage:   (1) v_imagescnu(log10(1:2:9),(1:3).^2,reshape(1:15,3,5));   % log x, quadratic y
               colorbar; axis xy;                                      % add colorbar + invert y-axis

  Inputs:  x(nx) or x(nx+1)    x-axis patch centres or boundaries
           y(ny) or y(ny+1)    y-axis patch centres or boundaries
           v(ny,nx)            Values to plot (if db is non-zero then abs(v) will be displayed)
           db                  dB range to plot relative to peak (+ve for mag, -ve for power, 0 [default] for linear scale)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function v_imagescnu(x,y,v,db)
0002 % Plot image with non-uniform rectangular patches
0003 %
0004 %  Usage:   (1) v_imagescnu(log10(1:2:9),(1:3).^2,reshape(1:15,3,5));   % log x, quadratic y
0005 %               colorbar; axis xy;                                      % add colorbar + invert y-axis
0006 %
0007 %  Inputs:  x(nx) or x(nx+1)    x-axis patch centres or boundaries
0008 %           y(ny) or y(ny+1)    y-axis patch centres or boundaries
0009 %           v(ny,nx)            Values to plot (if db is non-zero then abs(v) will be displayed)
0010 %           db                  dB range to plot relative to peak (+ve for mag, -ve for power, 0 [default] for linear scale)
0011 %
0012 if nargin<4
0013     db=0;                                   % default to linear scale
0014 end
0015 [ny,nx]=size(v);
0016 x=x(:)';                                    % make x a row vector
0017 y=y(:)';                                    % make y a row vector
0018 if length(x)==nx                            % need to convert from column-centres to column-edges
0019     if nx==1                                % if only one column ...
0020         x=x-0.5:x+0.5;                      % ... make it of unit width
0021     else
0022         x=0.5*[3*x(1)-x(2) x(1:nx-1)+x(2:nx) 3*x(nx)-x(nx-1)];  % place column-edges midway between centres
0023     end
0024 elseif length(x)~=nx+1                      % error unless length(x) = either nx or nx+1
0025     error('size(v)=(%d,%d) so length(x) must be %d or %d',ny,nx,nx,nx+1);
0026 end
0027 if any(x(2:nx+1)-x(1:nx)<=0)                % check that x is monotonically increasing
0028     error('x values must be monotonically increasing');
0029 end
0030 if length(y)==ny                            % need to convert from row-centres to row-edges
0031     if ny==1                                % if only one row ...
0032         y=y-0.5:y+0.5;                      % ... make it of unit width
0033     else
0034         y=0.5*[3*y(1)-y(2) y(1:ny-1)+y(2:ny) 3*y(ny)-y(ny-1)];  % place row-edges midway between centres
0035     end
0036 elseif length(y)~=ny+1                      % error unless length(y) = either ny or ny+1
0037     error('size(v)=(%d,%d) so length(y) must be %d or %d',ny,nx,ny,ny+1);
0038 end
0039 if any(y(2:ny+1)-y(1:ny)<=0)                % check that y is monotonically increasing
0040     error('y values must be monotonically increasing');
0041 end
0042 if db~=0                                    % db nonzero means a log colour scale
0043     v=abs(v); 
0044     dbmul=(db>0)*10+10;                     % db multiplier is 10 for power (db<0) or 20 for magnitude (db>0)
0045     v=dbmul*log10(max(v,max(v(:))*10^(-abs(db)/dbmul)));    % clip data to a range of abs(db)
0046 end
0047 ix=reshape(repmat(1:nx,ny,1),1,nx*ny);      % x index of each patch (column-major order)
0048 iy=reshape(repmat((1:ny),1,nx),1,nx*ny);    % y index of each patch (column-major order)
0049 patx=[x(ix);x(ix+1);x(ix+1);x(ix)];         % x-coordinates of patch corners in order low-left, low-right, high-right, high-left(one patch per column)
0050 paty=[y(iy);y(iy);y(iy+1);y(iy+1)];         % y-coordinates of patch corners in order low-left, low-right, high-right, high-left(one patch per column)
0051 if ~ishold
0052     cla;                                    % clear the axes unless hold is turned on
0053 end
0054 patch(patx,paty,v(:),'EdgeColor', 'none');  % plot the patches
0055 axis([x(1) x(nx+1) y(1) y(ny+1)]);          % define the axis limits
0056 axis ij;                                    % orient image to conform to imagesc()

Generated by m2html © 2003