% 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 strangle 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'. % 2006-03-27 Created by Patrick Eriksson. function rectgridplot(x,y,F,shadtype) %= Default arguments % shadtype_DEFAULT = 'flat'; % set_defaults; %= Check input % if length(x)-size(F,1) ~= 1 error('Size mismatch between *x* and *F*.'); end if length(y)-size(F,2) ~= 1 error('Size mismatch between *y* and *F*.'); end if strcmp(shadtype,'flat') | strcmp(shadtype,'faceted') % pcolor( x, y, [ F F(:,end); F(end,:) F(end,end) ]' ); elseif strcmp(shadtype,'interp') % pcolor( [x(1) edges2grid(x) x(end)], [y(1) edges2grid(y) y(end)], ... [ F(1,1) F(1,:) F(1,end); F(:,1) F F(:,end); F(end,1) F(end,:) F(end,end) ]' ); else error('Valid shading types are ''flat'', ''faceted'' and ''interp'''); end shading(shadtype) set(gcf,'Renderer','OpenGL')