function []=cdatamidlev(h,v,scale)


error(nargchk(2,3,nargin))
error(nargoutchk(0,0,nargout))

if nargin<3
  scale='linear';
end

switch lower(scale)
  case 'linear'
    vm=[(v(1:end-1)+v(2:end))/2];
  case 'nonlinear'
    vm=linspace(v(1),v(end),2*length(v)-1);
    vm=vm(2:2:end);
  otherwise
    error(['Invalid scale ' scale])
end

hp=[];
hpind(1)=0;
for n=1:length(v)-1
  hp=[hp;findobj(h,'type','patch','cdata',v(n))];
  hpind(n+1)=length(hp);
end
for n=1:length(v)-1
  set(hp(hpind(n)+1:hpind(n+1)),'cdata',vm(n));
end
set(findobj(h,'type','patch','facecolor',get(gca,'color')), ...
    'facecolor','flat','cdata',-inf,'facevertexcdata',-inf);
