function [cout,hp] = contourf(arg1,arg2,arg3,arg4,arg5) % CONTOURF Filled contour plot. % Similar to CONTOUR command but fills the space between % contour lines with uniform color (according to the % figure colormap) instead of just contour lines. % Syntax is similar to the CONTOUR command. % CONTOURF(Z), CONTOURF(X,Y,Z), CONTOURF(Z,N), % CONTOURF(Z,V) and CONTOURF(X,Y,Z,V) are valid options. % Also allows CONTOURF(...,EC) where EC is the edgecolor of % patches (contour lines); EC should be a string such as % 'r','g','b','y','c','m','w','k', or 'none'. % [C,H] = CONTOURF(...) returns contour matrix C and % handles H of patches used in filling between contours. % For correct results needs auxillary program ISINPOLY.M % Copyright (c) 1995 by Kirill K. Pankratov % kirill@plume.mit.edu % 9/2/94, 10/25/94 % Revised 12/01/94 (bug found by Dr. Phil Morgan, % morgan@ml.csiro.au) % Defaults and parameters ...................................... edgecolordflt = 'k'; % Edge color of patches % Check if auxillary file ISINPOLY around ishere = exist('isinpoly'); % Handle input ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ if nargin < 1, error('Not enough input arguments.'), end isxy = 0; if nargin>2 if any(size(arg1)==1)&any(size(arg2)==1), isxy = 1; end end if isxy % If vectors x and y are input x = arg1; y = arg2; z = arg3; else % The first argument is matrix z z = arg1; [ly,lx] = size(z); x = 1:lx; y = 1:ly; end % Get edgecolor argument if input ......................... last_arg = []; edgecolor = ''; if nargin>1, last_arg = eval(['arg' num2str(nargin)]); end is = isstr(last_arg); if is last_arg = last_arg(last_arg>='a'); if last_arg~=[], edgecolor = last_arg; end end if edgecolor=='', edgecolor = edgecolordflt; else nargin = nargin-1; end % Sizes and limits ........................................ lx = length(x); ly = length(y); xmin = min(x); xmax = max(x); ymin = min(y); ymax = max(y); % Pass arguments to the CONTOUR program ................... arguments = 'arg1'; for jj = 2:nargin arguments = [arguments ',arg' num2str(jj)]; end eval(['[cc,hl] = contour(' arguments ');']); % Check all contours for "open/closed" ^^^^^^^^^^^^^^^^^^^^^^^^^ lcc = length(cc); jj = 1; jc = 1; % Initialize while jj=lx); xsq = x(fndc); fndc = max([max(find(y<=ccoord(2,1))) 1]); % y fndc = [fndc fndc+1]-(fndc>=ly); ysq = y(fndc); xsq = xsq([1 2 2 1]); % Make a rectangle ysq = ysq([1 1 2 2]); is = isinpoly(xsq,ysq,ccoord(1,:),ccoord(2,:)); % Is inside fndc = find(is~=.5); % Discard pts. on the contour if fndc~=[], fndc = fndc(1); else, fndc = 1; end is = is(fndc); nx = find(xsq(fndc)==x); ny = find(ysq(fndc)==y); zis = z(ny,nx); ismore = (zis>zin(1)&is)|(ziszopenmax; % Find which contours are inside which ............... fnd = find(~open&~out); lfnd = length(fnd); ind = ones(lfnd,1); isin = cmax(fnd,ind); isin = isincmin(fnd,2*ind)'); isin = isin&(cmin(fnd,ind)>cmin(fnd,ind)'); [isin,ind] = sort(-sum(isin)); if fnd==[], ind=[]; end num = 1:min(find(~out))-1; nc = max(find(~out))+1; num = [fnd(ind) fliplr(num)]; ismore = zeros(size(num)); num = [num nc:ncont]; ismore = [ismore ones(size(nc:ncont))]; for jj = 1:length(num) % Make all "closed" patchs `````````` 1 nc = num(jj); numc = nb(nc):ne(nc); ccoord = cc(:,numc); % Find points inside or outside ...................... if ~out(nc)&ishere % Find 4 grid pts. surrounding the first point of a contour fndc = max([max(find(x<=ccoord(1,1))) 1]); % x fndc = [fndc fndc+1]-(fndc>=lx); xsq = x(fndc); fndc = max([max(find(y<=ccoord(2,1))) 1]); % y fndc = [fndc fndc+1]-(fndc>=ly); ysq = y(fndc); xsq = xsq([1 2 2 1]); % Make a rectangle ysq = ysq([1 1 2 2]); is = isinpoly(xsq,ysq,ccoord(1,:),ccoord(2,:)); % Is inside fndc = find(is~=.5); % Discard pts on the contours if fndc~=[], fndc = fndc(1); else, fndc = 1; end is = is(fndc); nx = find(xsq(fndc)==x); ny = find(ysq(fndc)==y); zis = z(ny,nx); ismore(jj) = (zis>zc(nc)&is)|(zis 0 cout = cc; hp = p(find(p)); end