function pos=iduilay(figwh,butwh,ftb,bbv,bbh,etf,lev,nobut,layers)
%IDUILAY Compute positions for nicely laid out uicontrols.
% 	fdigwh  figure width & height
% 	butwh   button width & height
% 	ftb     frame to button
% 	bb      between buttons
% 	etf     edge to frame
% 	nobut   numerb of buttons
% 	layers  number of layers
%	POS: A matrix containing the positions of the surrounding frame,
%	and the correspodning nobut uicontrols.

%	L. Ljung 4-4-94
%	Copyright (c) 1986-95 by the MathWorks, Inc.
%	$Revision: 1.3 $  $Date: 1995/05/10 21:36:59 $

if nargin<9,layers=1;end
nobutw=ceil(nobut/layers);
framewidth=nobutw*butwh(1)+(nobutw-1)*bbh+2*ftb;
etf2=[figwh(1)-framewidth]/2;
pos(1,:)=[etf2 lev  framewidth layers*butwh(2)+(layers-1)*bbv+ftb*2];
kcount=1;
for kl=layers:-1:1
  for kb=1:nobutw
     kcount=kcount+1;
     pos(kcount,:)=[etf2+ftb+(kb-1)*(bbh+butwh(1))...
                    ftb+(kl-1)*(bbv+butwh(2))+lev butwh];
  end
end
