% KDEDEMO2    Demonstrate UIControls with 2D Kernel Density Estimates.
%
%             Example: data=randn(500,2); (optional - defines data)
%                      kdedemo2    
%
%             Menus: (a) DATA - A choice of three 2D data sets.
%                    (b) ROT. MOVIE - Create a rotational animation.
%                    (c) CONT. MOVIE - Create a contour based movie.
%                    (d) CONT. COL. - Defines the colour of contours.
%                    (e) COLOUR - A choice of several colormaps.
%
%             Pop-ups: (a) KERNEL - A choice of several well-known 2D kernel functions.
%                      (b) PLOT - Choice of Surface, Contour, Percentage Contour or 
%                                 Outlier plots.
%                      (c) HSELECT - A choice of several data-based h selection strategies.
%
%             Check-boxes: (a) ADAPTIVE - Turns adaptive method on/off,
%                          (b) SHADNG - Turns interpolated shading on/off.
%                          (c) HOLD - Toggle hold state.
%                          (d) SCATTER - Add scatter plot.
%
%             Push buttons: (a) END - Quit demonstration,
%                           (b) VIEW2 - Standard 2D view.
%                           (c) VIEW3 - Standard 3D view.
%
%             Sliders: (a) LR - Sets azimuth angle of view,
%                      (b) UD - Sets elevation angle of view.
%
%             Editable text: (a) H - Click here to enter a value for H.  Values 
%                                of H=0 cause the routine to use an 'optimal' 
%                                value.  If entering >1 value use vector notation, 
%                                eg [2,1] or [2,0].
%                            (b) CONTOUR PERCENTAGES - eg [25,50,75] or [50,100] or
%                                [10:10:90]. 
% 
%             Christian C. Beardah 1995  

echo off

load kddata;
load nmd2;

if exist('data')==0,
  data=lukesh1(:,[2,5]);
  import=0;
  else,
    data=data(:,1:2);
    import=1;
end;

% Initialise

cframes=18;
continc=5;
rframes=24;
angle=360/rframes;

kernel='knorm';

if exist('nmesh')==0,
  nmesh=64;
end;

azim=-37.5;
elev=30;
adapt=0;

% Choose default h selection algorithm (see also Pop-up menu section below):

h=[hns(data(:,1),kernel) hns(data(:,2),kernel)];
% h=[hste(data(:,1),kernel) hste(data(:,2),kernel)];

figure('Name','Bi-variate KDE demo');

% x,y are vectors, z a matrix

[x,y,z]=kdfft2(data,kernel,nmesh,h);

pc=[25,50,75];
ddata=kdint2(data,x,y,z); 
wt=pclevel(pc,ddata); 
col='y';

xlabel('x');
ylabel('y');
zlabel('Density');

view(azim,elev);
axvec=axis;
set(gca,'box','on');

% Callback strings

ends = 'clear global; clear; load kddata; load nmd2; close;';

smooths = 'if get(smoothh,''value'')==1, shading interp; else, shading faceted; end; ';

lights = 'if get(lighth,''value'')==1, light; lighting gouraud; else, lighting none; end; ';

calcs = 'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata);';

holds = 'if get(holdh,''value'')==1, hold on; else, hold off; end;';

dview2s = 'view(2); set(udc,''value'',90); set(lrc,''value'',0); azim=0; elev=90;';

dview3s = 'view(3); set(udc,''value'',30); set(lrc,''value'',-37.5); azim=-37.5; elev=30;';

moviers = 'M = moviein(rframes); for j=1:rframes, view(azim+j*angle,elev); axis(axvec); M(:,j) = getframe; end;';

playrs = ['movie(M,10,10);',dview3s];

scatters = ['v=get(ploth,''value''); if v==2 | v==5, if get(scatterh,''value'')==1, hold on; plot(data(:,1),data(:,2),''wx'');',... 
            'hold off; else, zmax=max(max(z)); cinc=zmax/10; contour3(x,y,z,[cinc:cinc:(zmax-cinc)],col); set(scatterh,''value'',0); end;',...
            'hold off; elev=90; set(udc,''value'',elev); view(azim,elev); end;',...
            'if v==3, if get(scatterh,''value'')==1, hold on; plot(data(:,1),data(:,2),''wx'');',... 
            'if exist(''outl''), [ro,co]=size(outl); for i=1:ro, text(outl(i,2),outl(i,3),int2str(outl(i,1))); end; end; hold off; else,',...
            'if get(holdh,''value'')==0, for i=1:length(pc), contour3(x,y,z,wt(i,:),col); if i==1, hold on; end; end;',...
            'hold off; elev=90; set(udc,''value'',elev); view(azim,elev);',...
            'set(scatterh,''value'',0); else, set(scatterh,''value'',1); end; end; end; if v==1 | v==4, set(scatterh,''value'',0); end;']; 

conts = [holds,'for i=1:length(pc), contour3(x,y,z,wt(i,:),col); if i==1, hold on; end; end; hold off;',...
         'if get(scatterh,''value'')==1, hold on, plot(data(:,1),data(:,2),''wx''); if exist(''outl''), [ro,co]=size(outl); for i=1:ro,',...
         'text(outl(i,2),outl(i,3),int2str(outl(i,1))); end; end; hold off; end;',...
         'elev=90; set(udc,''value'',elev); view(azim,elev);']; 

moviecs = ['N = moviein(cframes); for j=1:cframes, plot(data(:,1),data(:,2),''wx'');',...
           'hold on; movwt=pclevel(100-j*continc,ddata); contour3(x,y,z,movwt,col);',...
           'if j==1, maxvec=axis; else, axis(maxvec); end; hold off; N(:,j) = getframe; end;',conts];

playcs = ['movie(N,-10,10);',conts];

% For surface plots instead of mesh plots change 'mesh' in the following line to 'surf'.
% The M-files kdfft2.m and kdplot.m will also need to be edited in the same way.

plots = ['v=get(ploth,''value''); if v<5, set(scatterh,''value'',0); end; if v==1, surf(x,y,z);',...
          smooths,lights,'if ~exist(''axvec''), axvec=axis; end; axis(axvec); set(gca,''box'',''on''); elseif v==2, zmax=max(max(z)); cinc=zmax/10; contour3(x,y,z,[cinc:cinc:(zmax-cinc)],col);',...
         'elev=90; set(udc,''value'',elev); elseif v==3, if ~exist(''wt''),',calcs,' end;',conts,...
         'elseif v==4, if ~exist(''ddata''),',calcs,' end; [outl,index]=outl2(max(pc),data,x,y,z,ddata); outl, plot(outl(:,5),outl(:,4),''wx'');',...
         '[ro,co]=size(outl); for i=1:ro, text(outl(i,5),outl(i,4),int2str(outl(i,1))); end; elev=90; set(udc,''value'',elev); view(azim,elev);',... 
         'elseif v==5, [in,vin]=hull2int(data); in(:,3)=kdint2(in,x,y,z); in(:,4)=vin; in(find(in(:,3)>=max(max(wt))),:), end;',...
         'view(azim,elev); if v~=4, xlabel(''x''); ylabel(''y''); zlabel(''Density''); else,',...
         'xlabel(''Minimum distance from outer contour''); ylabel(''Density''); end;',...
         'if length(h)==3, title([''h = '',num2str(h(1)),'' , '',num2str(h(2)),'' , '',num2str(h(3))]);',...
         'elseif length(h)==2, title([''h = '',num2str(h(1)),'' , '',num2str(h(2))]);',...
         'else, title([''h = '',num2str(h)]); end;'];

hselects = ['clear wt outl; v=get(hselecth,''value''); if v==1, h=[hns(data(:,1),kernel) hns(data(:,2),kernel)];',...
           'elseif v==2 & kernel==''knorm'', h=[hdpi(data(:,1),kernel,1) hdpi(data(:,2),kernel,1)];',...
           'elseif v==3 & kernel==''knorm'', h=[hdpi(data(:,1),kernel,2) hdpi(data(:,2),kernel,2)];',...
           'elseif v==4 & kernel==''knorm'', h=[hdpi(data(:,1),kernel,3) hdpi(data(:,2),kernel,3)];',...
           'elseif v==5 & kernel==''knorm'', h=[hste(data(:,1),kernel) hste(data(:,2),kernel)];',...
           'elseif v==6 & kernel==''knorm'', h=h2dpi(data,kernel,0);',...
           'elseif v==7 & kernel==''knorm'', h=h2dpi(data,kernel,1);',...
           'elseif v==8 & kernel==''knorm'', h=h2dpi(data,kernel,2);',...
           'elseif v==9 & kernel==''knorm'', h=h2dpi(data,kernel,3);',...
           'elseif v==10 & kernel==''knorm'', h=hbcv2(data,kernel);',...
           'else, h=[hns(data(:,1),kernel) hns(data(:,2),kernel)];',...  
           'set(hselecth,''value'',1); end; set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
           'if adapt==0, [x,y,z]=kdfft2(data,kernel,nmesh,h,0);',...
           'else, [x,y,z,h]=kdplot(data,kernel,nmesh,adapt,h,0); end;',calcs,plots];

hvals = ['h=str2num(get(hvalh,''string'')); if adapt==0 & length(h)<3, [x,y,z]=kdfft2(data,kernel,nmesh,h,0);',...
         'clear wt outl;',calcs,plots,'else, [x,y,z,h]=kdplot(data,kernel,nmesh,adapt,h,0); clear wt outl;',calcs,plots,'end;'];

adapts = ['if get(adapth,''value'')==1, adapt=1; else, adapt=0; end; clear wt outl;',hvals];

pcvals = ['pc=str2num(get(pcvalh,''string'')); if min(pc)<0, disp(''ERROR - negative contour level'');',...
         'else, clear outl; wt=pclevel(pc,ddata); end; set(ploth,''value'',3);',plots];

meshs = ['nmesh=str2num(get(meshh,''string'')); if nmesh<8, disp(''ERROR - mesh too small'');',...
         'else, if adapt==0, [x,y,z]=kdfft2(data,kernel,nmesh,h,0);',...
         'else, [x,y,z,h]=kdplot(data,kernel,nmesh,adapt,h,0); end; clear wt outl;',calcs,plots,'end;'];

kerpops = ['clear wt outl; v=get(kerpoph,''value''); if v==1, kernel=''knorm'';',...
           'elseif v==2, kernel=''kepan'';',...
           'elseif v==3, kernel=''kbiwe'';',...
           'elseif v==4, kernel=''ktriw'';',...
           'elseif v==5, kernel=''ktria'';',...
           'elseif v==6, kernel=''krect''; end;', hselects];

plotmaxs = ['[pmax,cmax]=bump2(x,y,z,0.01); pmax, hold on; plot(pmax(:,1),pmax(:,2),''ro'');', holds];

maxs = ['v=get(maxh,''value''); if v==1 & (get(ploth,''value'')==2 | get(ploth,''value'')==3),',...
        plotmaxs, 'elseif v==1 & (get(ploth,''value'')==1 | get(ploth,''value'')==4), set(maxh,''value'',0);',...
        'else,', plots, 'end;', holds];

% Frames

frame1h = uicontrol('style','frame','units','normal','pos',[.84 .73 .15 .2]);

frame2h = uicontrol('style','frame','units','normal','pos',[.02 .02 .175 .1]);

% Check boxes

adapth = uicontrol('style','checkbox','units','normal','pos',[.85 .86 .125 .05],...
  'string','Adaptive','call',adapts);
smoothh = uicontrol('style','checkbox','units','normal','pos',[.02 .875 .125 .05],...
  'string','Shading','call',smooths);
lighth = uicontrol('style','checkbox','units','normal','pos',[.16 .875 .125 .05],...
  'string','Lighting','call',lights);
scatterh = uicontrol('style','checkbox','units','normal','pos',[.02 .14 .125 .05],...
  'string','Scatter','call',scatters);
holdh = uicontrol('style','checkbox','units','normal','pos',[.02 .21 .09 .05],...
  'string','Hold','call',holds);
maxh = uicontrol('style','checkbox','units','normal','pos',[.02 .805 .09 .05],...
  'string','Max','call',maxs);

% Pop-up menus

kerpoph = uicontrol('style','popupmenu','units','normal','pos',[.8 .91 .185 .08],...
  'string','Normal|Epanechnikov|Biweight_P|Triweight_P|Triangular_P|Rectangular_P','call',kerpops);   
ploth = uicontrol('style','popupmenu','units','normal','pos',[.0175 .91 .24 .08],...
  'string','Surface|Contour|Percent Contour|Outliers|In convex hull','call',plots);   
hselecth = uicontrol('style','popupmenu','units','normal','pos',[.8 .64 .19 .08],...
  'string','Univariate NS|Univariate DPI 1|Univariate DPI 2|Univariate DPI 3|Univariate STE2|Bivariate DPI 0|Bivariate DPI 1|Bivariate DPI 2|Bivariate DPI 3|Bivariate BiasCV',...
  'call',hselects);

% Choose default h selection algorithm (1 - NS, 5 - STE):

set(hselecth,'value',1);
% set(hselecth,'value',5);

% Menus

datamenus = ['clear M N; axvec=axis; set(gca,''box'',''on'');',...
             'set(glassh,''checked'',''off''),',...
             'set(cuph,''checked'',''off''),',...
             'set(n01h,''checked'',''off''),',...
             'set(lmh,''checked'',''off''),',...
             'set(leadh,''checked'',''off''),',...
             'set(smallh,''checked'',''off''),',...
             'set(nmd2ah,''checked'',''off''),',...
             'set(nmd2bh,''checked'',''off''),',...
             'set(nmd2ch,''checked'',''off''),',...
             'set(nmd2dh,''checked'',''off''),',...
             'set(nmd2eh,''checked'',''off''),',...
             'set(nmd2fh,''checked'',''off''),',...
             'set(nmd2gh,''checked'',''off''),',...
             'set(nmd2hh,''checked'',''off''),',...
             'set(nmd2ih,''checked'',''off''),',...
             'set(nmd2jh,''checked'',''off''),',...
             'set(nmd2kh,''checked'',''off''),',...
             'set(nmd2lh,''checked'',''off''),',...
             'set(nmd2mh,''checked'',''off''),',...
             'set(maskh,''checked'',''off'');'];

datamenuh = uimenu(gcf,'label','Data');

glassh = uimenu(datamenuh,'label','Glass Chemistry (361)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=[glass(:,5) glass(:,8)];',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(glassh,''checked'',''on'')']);
maskh = uimenu(datamenuh,'label','Artifact Locations (276)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=mask4;',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(maskh,''checked'',''on'')']);
cuph = uimenu(datamenuh,'label','Cup Diam./Height (60)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=lukesh1(:,[2,5]);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(cuph,''checked'',''on'')']);
lmh = uimenu(datamenuh,'label','Leic/Manc (105)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=lmpc(:,1:2);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(lmh,''checked'',''on'')']);
leadh = uimenu(datamenuh,'label','Lead Isotope (62)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=kea(:,1:2);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(leadh,''checked'',''on'')']);
n01h = uimenu(datamenuh,'label','N(0,1) (500)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=randn(500,2);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(n01h,''checked'',''on'')']);
smallh = uimenu(datamenuh,'label','Small (5)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=small2;',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(smallh,''checked'',''on'')']);
nmd2ah = uimenu(datamenuh,'label','Mixture Density A (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wa,sigmaa,mua);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2ah,''checked'',''on'')']);
nmd2bh = uimenu(datamenuh,'label','Mixture Density B (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wb,sigmab,mub);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2bh,''checked'',''on'')']);
nmd2ch = uimenu(datamenuh,'label','Mixture Density C (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wc,sigmac,muc);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2ch,''checked'',''on'')']);
nmd2dh = uimenu(datamenuh,'label','Mixture Density D (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wd,sigmad,mud);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2dh,''checked'',''on'')']);
nmd2eh = uimenu(datamenuh,'label','Mixture Density E (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,we,sigmae,mue);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2eh,''checked'',''on'')']);
nmd2fh = uimenu(datamenuh,'label','Mixture Density F (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wf,sigmaf,muf);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2fh,''checked'',''on'')']);
nmd2gh = uimenu(datamenuh,'label','Mixture Density G (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wg,sigmag,mug);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2gh,''checked'',''on'')']);
nmd2hh = uimenu(datamenuh,'label','Mixture Density H (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wh,sigmah,muh);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2hh,''checked'',''on'')']);
nmd2ih = uimenu(datamenuh,'label','Mixture Density I (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wi,sigmai,mui);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2ih,''checked'',''on'')']);
nmd2jh = uimenu(datamenuh,'label','Mixture Density J (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wj,sigmaj,muj);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2jh,''checked'',''on'')']);
nmd2kh = uimenu(datamenuh,'label','Mixture Density K (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wk,sigmak,muk);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2kh,''checked'',''on'')']);
nmd2lh = uimenu(datamenuh,'label','Mixture Density L (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wl,sigmal,mul);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2lh,''checked'',''on'')']);
nmd2mh = uimenu(datamenuh,'label','Mixture Density M (200)','callback',...
  ['clear wt outl axvec; set(scatterh,''value'',0); data=snmd2(200,wm,sigmam,mum);',hselects,...
   'ddata=kdint2(data,x,y,z); wt=pclevel(pc,ddata); set(hvalh,''string'',[''['',num2str(h(1)),'','',num2str(h(2)),'']'']);',...
    plots,datamenus,'set(nmd2mh,''checked'',''on'')']);

if import==0,
  set(cuph,'checked','on');
end;

colmenus = ['set(yellowh,''checked'',''off''),',...
            'set(redh,''checked'',''off''),',...
            'set(whiteh,''checked'',''off''),',...
            'set(blueh,''checked'',''off''),',...
            'set(magentah,''checked'',''off''),',...
            'set(cyanh,''checked'',''off''),',...
            'set(greenh,''checked'',''off'');'];

colmenuh = uimenu(gcf,'label','Cont. col.');

yellowh = uimenu(colmenuh,'label','Yellow','callback',...
  ['col=''y'';', colmenus, 'set(yellowh,''checked'',''on'')']);
redh = uimenu(colmenuh,'label','Red','callback',...
  ['col=''r'';', colmenus, 'set(redh,''checked'',''on'')']);
whiteh = uimenu(colmenuh,'label','White','callback',...
  ['col=''w'';', colmenus, 'set(whiteh,''checked'',''on'')']);
blueh = uimenu(colmenuh,'label','Blue','callback',...
  ['col=''b'';', colmenus, 'set(blueh,''checked'',''on'')']);
magentah = uimenu(colmenuh,'label','Magenta','callback',...
  ['col=''m'';', colmenus, 'set(magentah,''checked'',''on'')']);
cyanh = uimenu(colmenuh,'label','Cyan','callback',...
  ['col=''c'';', colmenus, 'set(cyanh,''checked'',''on'')']);
greenh = uimenu(colmenuh,'label','Green','callback',...
  ['col=''g'';', colmenus, 'set(greenh,''checked'',''on'')']);

set(yellowh,'checked','on');

colormen;

movrmenuh = uimenu(gcf,'label','Movie(R)');

formrh = uimenu(movrmenuh,'label','Create','callback',moviers);
playrh = uimenu(movrmenuh,'label','Play','callback',playrs);
clearrh = uimenu(movrmenuh,'label','Clear','callback',['clear M']);

movcmenuh = uimenu(gcf,'label','Movie(C)');

formch = uimenu(movcmenuh,'label','Create','callback',moviecs);
playch = uimenu(movcmenuh,'label','Play','callback',playcs);
clearch = uimenu(movcmenuh,'label','Clear','callback',['clear N']);

% Sliders

lrc = uicontrol('style','slider','units','normal','pos',[.35 .02 .25 .04],...
     'min',-90,'max',90,'value',azim,...
     'call',['azim = ceil(get(lrc,''value''));',... 
     'set(lrc,''value'',azim);',plots;]);
lrmin = uicontrol('style','text','units','normal','pos',[.305 .02 .04 .04],...
     'string',num2str(get(lrc,'min')));
lrmax = uicontrol('style','text','units','normal','pos',[.605 .02 .04 .04],...
     'string',num2str(get(lrc,'max')));

udc = uicontrol('style','slider','units','normal','pos',[.945 .36 .04 .25],...
     'min',0,'max',90,'value',elev,...
     'call',['elev = ceil(get(udc,''value''));',... 
     'set(udc,''value'',elev);',plots;]);
udmin = uicontrol('style','text','units','normal','pos',[.945 .32 .04 .035],...
     'string',num2str(get(udc,'min')));
udmax = uicontrol('style','text','units','normal','pos',[.945 .615 .04 .035],...
     'string',num2str(get(udc,'max')));

% Push buttons

endh = uicontrol('style','push','units','normal','pos',[.91 .02 .08 .06],...
        'string','End','call',ends);
dview2h = uicontrol('style','push','units','normal','pos',[.81 .02 .08 .06],...
        'string','View2','call',dview2s);
dview3h = uicontrol('style','push','units','normal','pos',[.91 .1 .08 .06],...
        'string','View3','call',dview3s);

% Editable text

hvalh = uicontrol('style','edit','units','normal','pos',[.885 .8 .09 .04],...
        'string','0.00','min',0,'call',hvals);
hvalt = uicontrol('style','text','units','normal','pos',[.86 .8 .02 .04],...
        'string','h:');

set(hvalh,'string',['[',num2str(h(1)),',',num2str(h(2)),']']);

pcvalh = uicontrol('style','edit','units','normal','pos',[.035 .03 .15 .04],...
        'string','[25,50,75]','min',0,'call',pcvals);
pcvalt = uicontrol('style','text','units','normal','pos',[.035 .07 .15 .04],...
        'string','Contour %''s:');

meshh = uicontrol('style','edit','units','normal','pos',[.92 .74 .05 .04],...
        'string',num2str(nmesh),'min',8,'call',meshs);
mesht = uicontrol('style','text','units','normal','pos',[.86 .74 .06 .04],...
        'string','mesh:');