Home > atmlab > geoplots > rectgridplot.m

rectgridplot

PURPOSE ^

RECTGRIDPLOT Plots a rectangular field

SYNOPSIS ^

function rectgridplot(x,y,F,varargin)

DESCRIPTION ^

 RECTGRIDPLOT   Plots a rectangular field

    A help function to plot a 2D rectangular field. The function uses *pcolor*
    and expands and shifts grids in such way that expected result is obtained.
    The renderer is also set to OpenGL as this has been found to give better
    performance.
    
    It is recommnded to use this function. First of you do not need to bother
    about required fixes for *pcolor*. The function *contourf* is easier to
    use but behaves strange when it comes to color limits.

    The data abscissas are defined with the edges of each grid cell. This
    means that the length of *x* and *y* shall be +1 compared to corresponding
    dimension of *F*. 

 FORMAT   rectgridplot(x,y,F[,shadtype])
        
 IN    x          Data edges in x-direction.
       y          Data edges in y-direction.
       F          Data field (size(F)=[length(x)-1,length(y)-1]).
 OPT   shadtype   Shading type. Default is 'flat'. Other options are 'faceted'
                  and 'interp'.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

rectgridplot.m

SOURCE CODE ^

0001 % RECTGRIDPLOT   Plots a rectangular field
0002 %
0003 %    A help function to plot a 2D rectangular field. The function uses *pcolor*
0004 %    and expands and shifts grids in such way that expected result is obtained.
0005 %    The renderer is also set to OpenGL as this has been found to give better
0006 %    performance.
0007 %
0008 %    It is recommnded to use this function. First of you do not need to bother
0009 %    about required fixes for *pcolor*. The function *contourf* is easier to
0010 %    use but behaves strange when it comes to color limits.
0011 %
0012 %    The data abscissas are defined with the edges of each grid cell. This
0013 %    means that the length of *x* and *y* shall be +1 compared to corresponding
0014 %    dimension of *F*.
0015 %
0016 % FORMAT   rectgridplot(x,y,F[,shadtype])
0017 %
0018 % IN    x          Data edges in x-direction.
0019 %       y          Data edges in y-direction.
0020 %       F          Data field (size(F)=[length(x)-1,length(y)-1]).
0021 % OPT   shadtype   Shading type. Default is 'flat'. Other options are 'faceted'
0022 %                  and 'interp'.
0023 
0024 % 2006-03-27   Created by Patrick Eriksson.
0025 
0026 
0027 function rectgridplot(x,y,F,varargin)
0028 %
0029 [shadtype] = optargs( varargin, { 'flat' } );
0030                                                                             %&%
0031                                                                             %&%
0032 %= Check input                                                              %&%
0033 %                                                                           %&%
0034 rqre_nargin( 3, nargin );                                                   %&%
0035 if length(x)-1 ~= size(F,1)                                                 %&%
0036   error( 'Length of *x* does not match size of *F*.' );                     %&%
0037 end                                                                         %&%
0038 if length(y)-1 ~= size(F,2)                                                 %&%
0039   error( 'Length of *y* does not match size of *F*.' );                     %&%
0040 end                                                                         %&%
0041 
0042 
0043 if strcmp(shadtype,'flat')  |  strcmp(shadtype,'faceted')
0044   %
0045   pcolor( x, y, [ F F(:,end); F(end,:) F(end,end) ]' );
0046 
0047 elseif strcmp(shadtype,'interp')
0048   %
0049   pcolor( [x(1) vec2row(edges2grid(x)) x(end)], ...
0050           [y(1) vec2row(edges2grid(y)) y(end)], ... 
0051       [ F(1,1)   F(1,:)   F(1,end); 
0052         F(:,1)   F        F(:,end); 
0053         F(end,1) F(end,:) F(end,end) ]' );
0054 
0055 else                                                                        %&%
0056   error('Valid shading types are ''flat'', ''faceted'' and ''interp''');    %&%
0057 end
0058 
0059 shading( shadtype )
0060 
0061 set( gcf, 'Renderer', 'zbuffer' );

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005