% DO NOT EDIT!  Generated automatically by dump_demos.m
function dump_plot_demos ()
set (0, 'DefaultAxesColorOrder', ...
  [ 0.00000   0.00000   1.00000 ;
    0.00000   0.50000   0.00000 ;
    1.00000   0.00000   0.00000 ;
    0.00000   0.75000   0.75000 ;
    0.75000   0.00000   0.75000 ;
    0.75000   0.75000   0.00000 ;
    0.25000   0.25000   0.25000 ]);
close all
set (0, "defaultfigurevisible", "off")
figure ();
set (gcf, "visible", "off")
more off
diary diary.log

function annotation_01 ()
    
 clf; axes ('visible', 'off');
 annotation ('textbox', [.25 .9 .5 .09], 'string', ...
             {'Right Click on annotation objects', ...
              'to customize their appearance'}, ...
             'horizontalalignment', 'center', 'fitboxtotext', 'off');
 annotation ('ellipse', [.2 .2 .6 .6], 'linewidth', 4);
 ang = pi/2:-pi/2:-pi;
 lab = {'N', 'W', 'S', 'E'};
 x0 = 0.5;
 y0 = 0.5;
 r = 0.3;
 for ii = 1:4
   x = r * cos (ang(ii)) + x0;
   y = r * sin (ang(ii)) + y0;
   annotation ('textarrow', [x x0], [y y0], ...
               'string', lab{ii},  'fontsize', 20);
 end

 h = annotation ('doublearrow', [x0 x0], [y0-r y0+r], ...
                 'head1style', 'diamond', 'head1length', 60, ...
                 'head2style', 'diamond', 'head2length', 60);

end

try
  if (~ exist ('annotation_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    annotation_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "annotation_01.png" ... ');
      tic ();
      print ('-dpng', 'annotation_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "annotation_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in annotation_01: %s\n', lasterr ());
  err_fid = fopen ('annotation_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function annotation_02 ()
    
 clf; axes ('visible', 'off');
 plot (1:10);
 xlabel ('X-LABEL');
 ylabel ('LARGE Y-LABEL', 'fontsize', 20);
 title ('FIGURE LAYOUT', 'fontsize', 24);

 ti = get (gca, 'tightinset');
 pos = get (gca, 'position');
 pos(1:2) = pos(1:2) - ti(1:2);
 pos(3) = pos(3) + ti (1) + ti (3);
 pos(4) = pos(4) + ti (2) + ti (4);

 ht = annotation ('textbox', pos, 'string', ' Position + tighinset', ...
                  'fitboxtotext', 'off', 'linestyle', '--', ...
                  'edgecolor', 'g', 'linewidth', 3, 'color', 'g', ...
                  'verticalalignment', 'bottom', 'fontsize', 15);

 ho = annotation ('textbox', get (gca, 'outerposition'), ...
                  'string', ' Outerposition','fitboxtotext', 'off', ...
                  'linestyle', '--', 'edgecolor', 'r', ...
                  'linewidth', 3, 'color', 'r', ...
                  'verticalalignment', 'bottom', 'fontsize', 15);

 hi = annotation ('textbox', get (gca, 'position'), ...
                  'string', ' Position','fitboxtotext', 'off', ...
                  'linestyle', '--', 'edgecolor', 'b', ...
                  'linewidth', 3, 'color', 'b', ...
                  'verticalalignment', 'bottom', 'fontsize', 15);

end

try
  if (~ exist ('annotation_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    annotation_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "annotation_02.png" ... ');
      tic ();
      print ('-dpng', 'annotation_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "annotation_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in annotation_02: %s\n', lasterr ());
  err_fid = fopen ('annotation_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function annotation_03 ()
    
 clf; axes ('visible', 'off');
 h = annotation ('arrow');

 %% Get allowed headstyles
 styles = set (h, 'headstyle');
 delete (h);

 %% Textbox for the title
 annotation ('textbox', [0.1 0 0.8 1], 'string', ...
             '"headstyle" property:', ...
             'backgroundcolor', [0.7 0.7 0.7], 'fontsize', 20, ...
             'fitboxtotext', 'off', 'verticalalignment', 'top', ...
             'horizontalalignment', 'center');

 %% Textarrows
 ns = numel (styles);
 nrows = ceil (ns/2);
 dy = 1/nrows;
 y = 1 - dy/2;

 jj = 1;
 for ii = 1:nrows
   annotation ('textarrow', [0.3 0.5], [y y], ...
               'string', styles{jj}, 'fontsize', 15, ...
               'headstyle', styles{jj}, 'textcolor', 'b');
   jj = jj + 1;
   if (jj <= ns)
     annotation ('textarrow', [0.7 0.5], [y y], ...
                 'string', styles{jj}, 'fontsize', 15, ...
                 'headstyle', styles{jj}, 'textcolor', 'b');
   jj = jj + 1;
   end
   y = y - dy;
 end
 annotation ('line', [0.5 0.5], [dy/2 1-dy/2], 'linestyle', '-.');

end

try
  if (~ exist ('annotation_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    annotation_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "annotation_03.png" ... ');
      tic ();
      print ('-dpng', 'annotation_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "annotation_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in annotation_03: %s\n', lasterr ());
  err_fid = fopen ('annotation_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function annotation_04 ()
    
 clf; axes ('visible', 'off');

 %% Textbox for the title
 annotation ('textbox', [0.1 0 0.8 1], 'string', ...
             'Text arrows: text rotation', ...
             'backgroundcolor', [0.7 0.7 0.7], 'fontsize', 20, ...
             'fitboxtotext', 'off', 'verticalalignment', 'top', ...
             'horizontalalignment', 'center');

 %% Textarrows
 for ii = 1:10
   rot = floor (rand (1) * 360 / 90) * 90;
   annotation ('textarrow', 0.5 + [(0.6 * (rand(1) - .5)) 0], ...
               0.5 + [(0.6 * (rand(1) - .5)) 0], ...
               'string', 'A text', ...
               'headstyle', 'none', 'textrotation', rot);
 end

end

try
  if (~ exist ('annotation_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    annotation_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "annotation_04.png" ... ');
      tic ();
      print ('-dpng', 'annotation_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "annotation_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in annotation_04: %s\n', lasterr ());
  err_fid = fopen ('annotation_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function annotation_05 ()
    
 clf; axes ('visible', 'off');

 %% Textbox for the title
 annotation ('textbox', [0.1 0 0.8 1], 'string', ...
             'Text arrows: text alignment', ...
             'backgroundcolor', [0.7 0.7 0.7], 'fontsize', 20, ...
             'fitboxtotext', 'off', 'verticalalignment', 'top', ...
             'horizontalalignment', 'center');

 %% Textarrows
 halig = {'right', 'center', 'left'};
 ii = 1;
 for x = .3:.2:.7
   annotation ('textarrow', [x .5], [.5 .9], ...
               'string', {'Multiple lines', 'text'}, ...
               'headstyle', 'none', 'horizontalalignment', halig{ii});
   ii = ii + 1;
 end

end

try
  if (~ exist ('annotation_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    annotation_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "annotation_05.png" ... ');
      tic ();
      print ('-dpng', 'annotation_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "annotation_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in annotation_05: %s\n', lasterr ());
  err_fid = fopen ('annotation_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function annotation_06 ()
    
 clf; axes ('visible', 'off');

 x = 0:0.01:2*pi;
 y = sin (x);
 plot (x, y);

 %% Extrema
 x0 = [pi/2 3*pi/2];
 y0 = [1 -1];

 %% Convert axes coordinates into normalized coordinates
 xl = xlim ();
 yl = [-1.2 1.5];
 ylim (yl);
 x0 = (x0 - xl(1)) / diff(xl);
 y0 = (y0 - yl(1)) / diff(yl);

 pos = get (gca (), 'position');
 x0 = x0*pos(3) + pos(1);
 y0 = y0*pos(4) + pos(2);


 %% Textarrows
 for ii = 1:2
   annotation ('doublearrow', [(x0(ii) - .05) (x0(ii) + .05)], ...
               [y0(ii) y0(ii)], 'head1style', 'vback3', ...
               'head2style', 'vback3', ...
               'head1width', 4, 'head2width', 4)
   h = annotation ('textarrow', [0.5 x0(ii)], [.85 y0(ii)], ...
                   'linestyle', '--', 'headstyle', 'none');
 end
 set (h, 'string', 'Extrema', 'fontsize', 15);
 title ('annotation() demo of TextArrows');

end

try
  if (~ exist ('annotation_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    annotation_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "annotation_06.png" ... ');
      tic ();
      print ('-dpng', 'annotation_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "annotation_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in annotation_06: %s\n', lasterr ());
  err_fid = fopen ('annotation_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axis_01 ()
    
 clf;
 t = 0:0.01:2*pi;
 x = sin (t);

 subplot (221);
  plot (t, x);
  title ('normal plot');

 subplot (222);
  plot (t, x);
  title ('axis square');
  axis ('square');

 subplot (223);
  plot (t, x);
  title ('axis equal');
  axis ('equal');

 subplot (224);
  plot (t, x);
  title ('normal plot again');
  axis ('normal');

end

try
  if (~ exist ('axis_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    axis_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axis_01.png" ... ');
      tic ();
      print ('-dpng', 'axis_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axis_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axis_01: %s\n', lasterr ());
  err_fid = fopen ('axis_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axis_02 ()
    
 clf;
 t = 0:0.01:2*pi;
 x = sin (t);

 subplot (121);
  plot (t, x);
  title ({'axis ij', 'Y-axis reversed'});
  axis ('ij');
  legend ('sine');

 subplot (122);
  plot (t, x);
  title ('axis xy');
  title ({'axis ij', 'Y-axis normal'});
  axis ('xy');
  legend ('sine');

end

try
  if (~ exist ('axis_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    axis_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axis_02.png" ... ');
      tic ();
      print ('-dpng', 'axis_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axis_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axis_02: %s\n', lasterr ());
  err_fid = fopen ('axis_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axis_03 ()
    
 clf;
 t = 0:0.01:2*pi;
 x = sin (t);

 subplot (331);
  plot (t, x);
  title ('x ticks and labels');
  axis ('ticx');

 subplot (332);
  plot (t, x);
  title ('y ticks and labels');
  axis ('ticy');

 subplot (333);
  plot (t, x);
  title ('axis off');
  axis ('off');

 subplot (334);
  plot (t, x);
  title ('x and y ticks, x labels');
  axis ('labelx','tic');

 subplot (335);
  plot (t, x);
  title ('x and y ticks, y labels');
  axis ('labely','tic');

 subplot (336);
  plot (t, x);
  title ('all ticks but no labels');
  axis ('nolabel','tic');

 subplot (337);
  plot (t, x);
  title ('x ticks, no labels');
  axis ('nolabel','ticx');

 subplot (338);
  plot (t, x);
  title ('y ticks, no labels');
  axis ('nolabel','ticy');

 subplot (339);
  plot (t, x);
  title ('all ticks and labels');
  axis ('on');

end

try
  if (~ exist ('axis_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    axis_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axis_03.png" ... ');
      tic ();
      print ('-dpng', 'axis_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axis_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axis_03: %s\n', lasterr ());
  err_fid = fopen ('axis_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axis_04 ()
    
 clf;
 t = 0:0.01:2*pi;
 x = sin (t);

 subplot (321);
  plot (t, x);
  title ('axes at [0 3 0 1]');
  axis ([0,3,0,1]);

 subplot (322);
  plot (t, x);
  title ('auto');
  axis ('auto');

 subplot (323);
  plot (t, x, ';sine [0:2pi];'); hold on;
  plot (-3:3,-3:3, ';line (-3,-3)->(3,3);'); hold off;
  title ('manual');
  axis ('manual');

 subplot (324);
  plot (t, x, ';sine [0:2pi];');
  title ('axes at [0 3 0 1], then autox');
  axis ([0,3,0,1]);
  axis ('autox');

 subplot (325);
  plot (t, x, ';sine [0:2pi];');
  title ('axes at [3 6 0 1], then autoy');
  axis ([3,6,0,1]);
  axis ('autoy');

 subplot (326);
  plot (t, sin(t), t, -2*sin(t/2));
  axis ('tight');
  title ('tight');

end

try
  if (~ exist ('axis_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    axis_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axis_04.png" ... ');
      tic ();
      print ('-dpng', 'axis_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axis_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axis_04: %s\n', lasterr ());
  err_fid = fopen ('axis_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axis_05 ()
    
 clf;
 x = 0:0.1:10;
 plot (x, sin(x));
 axis image;
 title ({'image', 'equivalent to "tight" & "equal"'});

end

try
  if (~ exist ('axis_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    axis_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axis_05.png" ... ');
      tic ();
      print ('-dpng', 'axis_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axis_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axis_05: %s\n', lasterr ());
  err_fid = fopen ('axis_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axis_06 ()
    
 clf;
 colormap ('default');
 [x,y,z] = peaks (50);
 x1 = max (x(:));
 pcolor (x-x1, y-x1/2, z);
 hold on;
 [x,y,z] = sombrero ();
 s = x1 / max (x(:));
 pcolor (s*x+x1, s*y+x1/2, 5*z);
 axis tight;
 title ('"tight" when two axes objects exist');

end

try
  if (~ exist ('axis_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    axis_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axis_06.png" ... ');
      tic ();
      print ('-dpng', 'axis_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axis_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axis_06: %s\n', lasterr ());
  err_fid = fopen ('axis_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axis_07 ()
    
 clf;
 loglog (1:20, '-s');
 axis tight;
 title ('"tight" on loglog plot');

end

try
  if (~ exist ('axis_07.png', 'file'))
    rand ('seed', 1);
    tic ();
    axis_07 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axis_07.png" ... ');
      tic ();
      print ('-dpng', 'axis_07.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axis_07.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axis_07: %s\n', lasterr ());
  err_fid = fopen ('axis_07.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function box_01 ()
    
 clf;
 plot (1:10, 'o-');
 box off;
 title ('box off');

end

try
  if (~ exist ('box_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    box_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "box_01.png" ... ');
      tic ();
      print ('-dpng', 'box_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "box_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in box_01: %s\n', lasterr ());
  err_fid = fopen ('box_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function box_02 ()
    
 clf;
 plot (1:10, 'o-');
 box on;
 title ('box on');

end

try
  if (~ exist ('box_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    box_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "box_02.png" ... ');
      tic ();
      print ('-dpng', 'box_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "box_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in box_02: %s\n', lasterr ());
  err_fid = fopen ('box_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function box_03 ()
    
 clf;
 z = [0:0.05:5];
 plot3 (cos (2*pi*z), sin (2*pi*z), z);
 box off;
 title ('box off');

end

try
  if (~ exist ('box_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    box_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "box_03.png" ... ');
      tic ();
      print ('-dpng', 'box_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "box_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in box_03: %s\n', lasterr ());
  err_fid = fopen ('box_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function box_04 ()
    
 clf;
 z = [0:0.05:5];
 plot3 (cos (2*pi*z), sin (2*pi*z), z);
 box on;
 set (gca, 'boxstyle', 'back');
 title ({'box on', 'boxstyle = "back"'});

end

try
  if (~ exist ('box_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    box_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "box_04.png" ... ');
      tic ();
      print ('-dpng', 'box_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "box_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in box_04: %s\n', lasterr ());
  err_fid = fopen ('box_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function box_05 ()
    
 clf;
 z = [0:0.05:5];
 plot3 (cos (2*pi*z), sin (2*pi*z), z);
 box on;
 set (gca, 'boxstyle', 'full');
 title ({'box on', 'boxstyle = "full"'});

end

try
  if (~ exist ('box_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    box_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "box_05.png" ... ');
      tic ();
      print ('-dpng', 'box_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "box_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in box_05: %s\n', lasterr ());
  err_fid = fopen ('box_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function camlookat_01 ()
    
 clf;
 [x, y, z] = peaks ();
 surf (x, y, z/5);
 hold on
 [x, y, z] = sphere ();
 s1 = surf (x/2, y/2+1.5, z/2+2);
 s2 = surf (x/5+0.2, y/5-2, z/5+1);
 axis equal
 axis tight
 title ('camlookat() demo #1');
 pause (1);
 camlookat (s1);
 pause (1);
 camlookat (s2);
 pause (1);
 camlookat ([s1 s2]);

end

try
  if (~ exist ('camlookat_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    camlookat_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "camlookat_01.png" ... ');
      tic ();
      print ('-dpng', 'camlookat_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "camlookat_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in camlookat_01: %s\n', lasterr ());
  err_fid = fopen ('camlookat_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function camorbit_01 ()
    
 clf;
 peaks ();
 title ('camorbit() demo #1');
 %% rotate the camera upwards
 camorbit (0, 30);
 %% rotate the camera right
 camorbit (20, 0);

end

try
  if (~ exist ('camorbit_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    camorbit_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "camorbit_01.png" ... ');
      tic ();
      print ('-dpng', 'camorbit_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "camorbit_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in camorbit_01: %s\n', lasterr ());
  err_fid = fopen ('camorbit_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function campos_01 ()
    
 clf;
 sphere ();
 title ('campos() demo #1');
 %% where is camera located?
 x1 = campos ()
 %% move the camera upwards
 campos (x1 + [0 0 2]);
 x2 = campos ()

end

try
  if (~ exist ('campos_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    campos_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "campos_01.png" ... ');
      tic ();
      print ('-dpng', 'campos_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "campos_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in campos_01: %s\n', lasterr ());
  err_fid = fopen ('campos_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function camroll_01 ()
    
 clf;
 peaks ();
 camroll (30);
 title ('camroll() demo #1');

end

try
  if (~ exist ('camroll_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    camroll_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "camroll_01.png" ... ');
      tic ();
      print ('-dpng', 'camroll_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "camroll_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in camroll_01: %s\n', lasterr ());
  err_fid = fopen ('camroll_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function camtarget_01 ()
    
 clf;
 sphere ();
 title ('camtarget() demo #1');
 %% where is camera pointing?
 x1 = camtarget ()
 %% point the camera upwards
 camtarget (x1 + [0 0 1]);
 x2 = camtarget ()

end

try
  if (~ exist ('camtarget_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    camtarget_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "camtarget_01.png" ... ');
      tic ();
      print ('-dpng', 'camtarget_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "camtarget_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in camtarget_01: %s\n', lasterr ());
  err_fid = fopen ('camtarget_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function camup_01 ()
    
 clf;
 sphere ();
 title ('camup() demo #1');
 %% what direction is 'up' for the camera?
 x1 = camup ()
 %% re-orient the camera with a new up-vector
 camup ([1 0 0]);
 x2 = camup ()

end

try
  if (~ exist ('camup_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    camup_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "camup_01.png" ... ');
      tic ();
      print ('-dpng', 'camup_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "camup_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in camup_01: %s\n', lasterr ());
  err_fid = fopen ('camup_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function camva_01 ()
    
 clf;
 peaks ();
 title ('camva() demo #1');
 %% query the viewing angle
 a1 = camva ()
 %% get a close-up view by decreasing the viewing angle:
 camva (0.5*a1);
 a2 = camva ()

end

try
  if (~ exist ('camva_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    camva_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "camva_01.png" ... ');
      tic ();
      print ('-dpng', 'camva_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "camva_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in camva_01: %s\n', lasterr ());
  err_fid = fopen ('camva_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function camzoom_01 ()
    
 clf;
 peaks ();
 camzoom (2);
 title ('camzoom() demo #1');

end

try
  if (~ exist ('camzoom_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    camzoom_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "camzoom_01.png" ... ');
      tic ();
      print ('-dpng', 'camzoom_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "camzoom_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in camzoom_01: %s\n', lasterr ());
  err_fid = fopen ('camzoom_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function clabel_01 ()
    
 clf;
 colormap ('default');
 [c, h] = contour (peaks (), -4:6);
 clabel (c, h, -4:2:6, 'fontsize', 12);
 title ('clabel() labeling every other contour');

end

try
  if (~ exist ('clabel_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    clabel_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "clabel_01.png" ... ');
      tic ();
      print ('-dpng', 'clabel_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "clabel_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in clabel_01: %s\n', lasterr ());
  err_fid = fopen ('clabel_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function clabel_02 ()
    
 clf;
 colormap ('default');
 [c, h] = contourf (peaks (), -7:6);
 clabel (c, h, -6:2:6, 'fontsize', 12);
 title ('clabel() labeling every other contour');

end

try
  if (~ exist ('clabel_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    clabel_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "clabel_02.png" ... ');
      tic ();
      print ('-dpng', 'clabel_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "clabel_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in clabel_02: %s\n', lasterr ());
  err_fid = fopen ('clabel_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function daspect_01 ()
    
 clf;
 x = 0:0.01:4;
 plot (x,cos(x), x,sin(x));
 axis square;
 daspect ([1 1 1]);
 title ('square plot box with axis limits [0, 4, -2, 2]');

end

try
  if (~ exist ('daspect_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    daspect_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "daspect_01.png" ... ');
      tic ();
      print ('-dpng', 'daspect_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "daspect_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in daspect_01: %s\n', lasterr ());
  err_fid = fopen ('daspect_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function daspect_02 ()
    
 clf;
 x = 0:0.01:4;
 plot (x,cos (x), x,sin (x));
 axis ([0 4 -1 1]);
 daspect ([2 1 1]);
 title ('square plot box with axis limits [0, 4, -1, 1]');

end

try
  if (~ exist ('daspect_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    daspect_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "daspect_02.png" ... ');
      tic ();
      print ('-dpng', 'daspect_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "daspect_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in daspect_02: %s\n', lasterr ());
  err_fid = fopen ('daspect_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function daspect_03 ()
    
 clf;
 x = 0:0.01:4;
 plot (x,cos(x), x,sin(x));
 daspect ([1 2 1]);
 pbaspect ([2 1 1]);
 title ('2x1 plot box with axis limits [0, 4, -2, 2]');

end

try
  if (~ exist ('daspect_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    daspect_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "daspect_03.png" ... ');
      tic ();
      print ('-dpng', 'daspect_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "daspect_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in daspect_03: %s\n', lasterr ());
  err_fid = fopen ('daspect_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function daspect_04 ()
    
 clf;
 x = 0:0.01:4;
 plot (x,cos(x), x, sin(x));
 axis square;
 set (gca, 'activepositionproperty', 'position');
 daspect ([1 1 1]);
 title ('square plot box with axis limits [0, 4, -2, 2]');

end

try
  if (~ exist ('daspect_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    daspect_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "daspect_04.png" ... ');
      tic ();
      print ('-dpng', 'daspect_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "daspect_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in daspect_04: %s\n', lasterr ());
  err_fid = fopen ('daspect_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function daspect_05 ()
    
 clf;
 x = 0:0.01:4;
 plot (x,cos(x), x,sin(x));
 axis ([0 4 -1 1]);
 set (gca, 'activepositionproperty', 'position');
 daspect ([2 1 1]);
 title ('square plot box with axis limits [0, 4, -1, 1]');

end

try
  if (~ exist ('daspect_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    daspect_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "daspect_05.png" ... ');
      tic ();
      print ('-dpng', 'daspect_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "daspect_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in daspect_05: %s\n', lasterr ());
  err_fid = fopen ('daspect_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function datetick_01 ()
    
 clf;
 yr = 1900:10:2000;
 pop = [76.094, 92.407, 106.461, 123.077 131.954, 151.868, 179.979, ...
        203.984, 227.225, 249.623, 282.224];
 plot (datenum (yr, 1, 1), pop);
 xlabel ('Year');
 ylabel ('US population (millions)');
 title ('datetick() with 4-digit year format');
 datetick ('x', 'YYYY');

end

try
  if (~ exist ('datetick_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    datetick_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "datetick_01.png" ... ');
      tic ();
      print ('-dpng', 'datetick_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "datetick_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in datetick_01: %s\n', lasterr ());
  err_fid = fopen ('datetick_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function datetick_02 ()
    
 clf;
 yr = 1988:2:2002;
 yr = datenum (yr,1,1);
 pr = [12.1 13.3 12.6 13.1 13.3 14.1 14.4 15.2];
 plot (yr, pr, '-o');
 xlabel ('year');
 ylabel ('average price');
 title ('datetick() with MM/DD/YY format');
 ax = gca;
 set (ax, 'xtick', datenum (1990:5:2005,1,1));
 datetick ('x', 2, 'keepticks');
 set (ax, 'ytick', 12:16);

end

try
  if (~ exist ('datetick_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    datetick_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "datetick_02.png" ... ');
      tic ();
      print ('-dpng', 'datetick_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "datetick_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in datetick_02: %s\n', lasterr ());
  err_fid = fopen ('datetick_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function grid_01 ()
    
 clf;
 subplot (3, 2, 1);
  plot (1:100);
  grid off;
  title ('grid off');
 subplot (3, 2, 2);
  plot (1:100);
  grid on;
  title ('grid on');
 subplot (3, 2, 3);
  plot (1:100);
  set (gca, 'xgrid', 'on');
  title ('xgrid on');
 subplot (3, 2, 4);
  plot (1:100);
  set (gca, 'ygrid', 'on');
  title ('ygrid on');
 subplot (3, 2, 5);
  plot (1:100);
  grid minor;
  title ('grid minor');
 subplot (3, 2, 6);
  plot (1:100);
  set (gca, 'yminorgrid', 'on');
  title ('yminorgrid on');

end

try
  if (~ exist ('grid_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    grid_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "grid_01.png" ... ');
      tic ();
      print ('-dpng', 'grid_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "grid_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in grid_01: %s\n', lasterr ());
  err_fid = fopen ('grid_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function grid_02 ()
    
 clf;
 subplot (2,2,1);
  semilogy (1:100);
  grid off;
  title ('grid off');
 subplot (2,2,2);
  semilogy (1:100);
  grid on;
  title ('grid on');
 subplot (2,2,3);
  semilogy (1:100);
  grid off;
  title ('no grid');
 subplot (2,2,4);
  semilogy (1:100);
  grid minor;
  title ('grid minor');

end

try
  if (~ exist ('grid_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    grid_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "grid_02.png" ... ');
      tic ();
      print ('-dpng', 'grid_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "grid_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in grid_02: %s\n', lasterr ());
  err_fid = fopen ('grid_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function grid_03 ()
    
 %% Display minor grid lines at major ticks
 clf;
 subplot (1,2,1)
  plot (1:10);
  set (gca, 'xminorgrid', 'on');
  set (gca, 'yminorgrid', 'on');
  title ({'major grid disabled',
          'minor grid displayed at major ticks'});
 subplot (1,2,2)
  semilogy (1:100);
  set (gca, 'xminorgrid', 'on');
  set (gca, 'yminorgrid', 'on');
  title ({'major grid disabled',
          'minor grid displayed at major ticks'});

end

try
  if (~ exist ('grid_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    grid_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "grid_03.png" ... ');
      tic ();
      print ('-dpng', 'grid_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "grid_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in grid_03: %s\n', lasterr ());
  err_fid = fopen ('grid_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function grid_04 ()
    
 clf;
 plot3 (1:10, 1:10, 1:10);
 set (gca, 'xtick', [0, pi/2, 4.7, 8, 10]);
 set (gca, 'ytick', [0, 1, pi, 7.3, 10]);
 set (gca, 'ztick', [0, exp(1), 5, 9.1, 10]);
 set (gca, 'xminorgrid', 'on');
 set (gca, 'yminorgrid', 'on');
 set (gca, 'zminorgrid', 'on');
 view (3);
 title ('Minor grid adapts to xticks (bug #45850)')

end

try
  if (~ exist ('grid_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    grid_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "grid_04.png" ... ');
      tic ();
      print ('-dpng', 'grid_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "grid_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in grid_04: %s\n', lasterr ());
  err_fid = fopen ('grid_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_01 ()
    
 clf;
 plot (rand (2));
 title ('legend called with string inputs for labels');
 h = legend ('foo', 'bar');
 legend (h, 'location', 'northeastoutside');
 set (h, 'fontsize', 20);

end

try
  if (~ exist ('legend_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_01.png" ... ');
      tic ();
      print ('-dpng', 'legend_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_01: %s\n', lasterr ());
  err_fid = fopen ('legend_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_02 ()
    
 clf;
 plot (rand (2));
 title ('legend called with cell array of strings');
 h = legend ({'cellfoo', 'cellbar'});
 legend (h, 'location', 'northeast');
 set (h, 'fontsize', 20);

end

try
  if (~ exist ('legend_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_02.png" ... ');
      tic ();
      print ('-dpng', 'legend_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_02: %s\n', lasterr ());
  err_fid = fopen ('legend_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_03 ()
    
 clf;
 plot (rand (3));
 title ('legend () without inputs creates default labels');
 h = legend ();

end

try
  if (~ exist ('legend_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_03.png" ... ');
      tic ();
      print ('-dpng', 'legend_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_03: %s\n', lasterr ());
  err_fid = fopen ('legend_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_04 ()
    
 clf;
 x = 0:1;
 plot (x,x,';I am Blue;', x,2*x, x,3*x,';I am yellow;');
 h = legend ('location', 'northeastoutside');
 %% Placing legend inside returns axes to original size
 legend (h, 'location', 'northeast');
 title ('Blue and Yellow keys, with Orange missing');

end

try
  if (~ exist ('legend_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_04.png" ... ');
      tic ();
      print ('-dpng', 'legend_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_04: %s\n', lasterr ());
  err_fid = fopen ('legend_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_05 ()
    
 clf;
 plot (1:10, 1:10, 1:10, fliplr (1:10));
 title ('incline is blue and decline is orange');
 legend ({'I am blue', 'I am orange'}, 'location', 'east');
 legend hide
 legend show

end

try
  if (~ exist ('legend_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_05.png" ... ');
      tic ();
      print ('-dpng', 'legend_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_05: %s\n', lasterr ());
  err_fid = fopen ('legend_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_06 ()
    
 clf;
 plot (1:10, 1:10, 1:10, fliplr (1:10));
 title ('Legend with keys in horizontal orientation');
 legend ({'I am blue', 'I am orange'}, ...
         'location', 'east', 'orientation', 'horizontal');
 legend boxoff
 legend boxon

end

try
  if (~ exist ('legend_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_06.png" ... ');
      tic ();
      print ('-dpng', 'legend_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_06: %s\n', lasterr ());
  err_fid = fopen ('legend_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_07 ()
    
 clf;
 plot (1:10, 1:10, 1:10, fliplr (1:10));
 title ('Legend with box off');
 legend ({'I am blue', 'I am orange'}, 'location', 'east');
 legend boxoff

end

try
  if (~ exist ('legend_07.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_07 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_07.png" ... ');
      tic ();
      print ('-dpng', 'legend_07.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_07.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_07: %s\n', lasterr ());
  err_fid = fopen ('legend_07.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_08 ()
    
 clf;
 plot (1:10, 1:10, 1:10, fliplr (1:10));
 title ('Legend with text to the left of key');
 legend ({'I am blue', 'I am orange'}, 'location', 'east');
 legend left

end

try
  if (~ exist ('legend_08.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_08 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_08.png" ... ');
      tic ();
      print ('-dpng', 'legend_08.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_08.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_08: %s\n', lasterr ());
  err_fid = fopen ('legend_08.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_09 ()
    
 clf;
 plot (1:10, 1:10, 1:10, fliplr (1:10));
 title ({'Use properties to place legend text to the left of key', ...
         'Legend text color is magenta'});
 h = legend ({'I am blue', 'I am orange'}, 'location', 'east');
 legend ('right');
 set (h, 'textposition', 'left');
 set (h, 'textcolor', [1 0 1]);

end

try
  if (~ exist ('legend_09.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_09 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_09.png" ... ');
      tic ();
      print ('-dpng', 'legend_09.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_09.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_09: %s\n', lasterr ());
  err_fid = fopen ('legend_09.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_10 ()
    
 clf;
 plot (1:10, 1:10, 1:10, fliplr (1:10));
 title ('Legend is hidden');
 legend ({'I am blue', 'I am orange'}, 'location', 'east');
 legend hide

end

try
  if (~ exist ('legend_10.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_10 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_10.png" ... ');
      tic ();
      print ('-dpng', 'legend_10.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_10.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_10: %s\n', lasterr ());
  err_fid = fopen ('legend_10.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_11 ()
    
 clf;
 x = 0:1;
 plot (x,x,';I am Blue;', x,2*x,';I am Orange;', x,3*x,';I am Yellow;');
 title ({'Labels are embedded in call to plot', ...
         'Legend is hidden and then shown'});
 legend boxon
 legend hide
 legend show

end

try
  if (~ exist ('legend_11.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_11 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_11.png" ... ');
      tic ();
      print ('-dpng', 'legend_11.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_11.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_11: %s\n', lasterr ());
  err_fid = fopen ('legend_11.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_12 ()
    
 clf;
 x = 0:1;
 plot (x,x,  x,2*x, x,3*x);
 title ('Labels with interpreted Greek text');
 h = legend ('\alpha', '\beta=2\alpha', '\gamma=3\alpha');
 set (h, 'interpreter', 'tex');

end

try
  if (~ exist ('legend_12.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_12 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_12.png" ... ');
      tic ();
      print ('-dpng', 'legend_12.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_12.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_12: %s\n', lasterr ());
  err_fid = fopen ('legend_12.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_13 ()
    
 clf;
 plot (rand (2));
 title ('Labels with TeX interpreter turned off');
 h = legend ('Hello_World', 'foo^bar');
 set (h, 'interpreter', 'none');

end

try
  if (~ exist ('legend_13.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_13 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_13.png" ... ');
      tic ();
      print ('-dpng', 'legend_13.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_13.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_13: %s\n', lasterr ());
  err_fid = fopen ('legend_13.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_14 ()
    
 clf;
 labels = {};
 colororder = get (gca, 'colororder');
 for i = 1:5
   h = plot (1:100, i + rand (100,1)); hold on;
   set (h, 'color', colororder(i,:));
   labels = {labels{:}, ['Signal ', num2str(i)]};
 end
 hold off;
 title ({'Signals with random offset and uniform noise';
         'Legend shown below and outside of plot'});
 xlabel ('Sample Nr [k]'); ylabel ('Amplitude [V]');
 legend (labels, 'location', 'southoutside');

end

try
  if (~ exist ('legend_14.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_14 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_14.png" ... ');
      tic ();
      print ('-dpng', 'legend_14.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_14.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_14: %s\n', lasterr ());
  err_fid = fopen ('legend_14.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_15 ()
    
 clf;
 x = linspace (0, 10);
 plot (x, x);
 hold on;
 stem (x, x.^2, 'g');
 title ('First created object gets first label');
 legend ('linear');
 hold off;

end

try
  if (~ exist ('legend_15.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_15 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_15.png" ... ');
      tic ();
      print ('-dpng', 'legend_15.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_15.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_15: %s\n', lasterr ());
  err_fid = fopen ('legend_15.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_16 ()
    
 clf;
 x = linspace (0, 10);
 plot (x, x, x, x.^2);
 title ('First created object gets first label');
 legend ('linear');

end

try
  if (~ exist ('legend_16.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_16 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_16.png" ... ');
      tic ();
      print ('-dpng', 'legend_16.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_16.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_16: %s\n', lasterr ());
  err_fid = fopen ('legend_16.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_17 ()
    
 clf;
 x = linspace (0, 10);
 plot (x, x, x, x.^2);
 title ('Labels are applied in order of object creation');
 legend ('linear', 'quadratic');

end

try
  if (~ exist ('legend_17.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_17 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_17.png" ... ');
      tic ();
      print ('-dpng', 'legend_17.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_17.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_17: %s\n', lasterr ());
  err_fid = fopen ('legend_17.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_18 ()
    
 clf;
 subplot (2,1,1);
 rand_2x3_data1 = [0.341447, 0.171220, 0.284370; 0.039773, 0.731725, 0.779382];
 bar (rand_2x3_data1);
 ylim ([0 1.0]);
 title ('legend() works for bar graphs (hggroups)');
 legend ({'1st Bar', '2nd Bar', '3rd Bar'}, 'location', 'northwest');
 subplot (2,1,2);
 x = linspace (0, 10, 20);
 stem (x, 0.5+x.*rand (size (x))/max (x), 'markeredgecolor', [0 0.7 0]);
 hold on;
 stem (x+10/(2*20), x.*(1.0+rand (size (x)))/max (x));
 xlim ([0 10+10/(2*20)]);
 title ('legend() works for stem plots (hggroups)');
 legend ({'Multicolor', 'Unicolor'}, 'location', 'northwest');

end

try
  if (~ exist ('legend_18.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_18 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_18.png" ... ');
      tic ();
      print ('-dpng', 'legend_18.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_18.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_18: %s\n', lasterr ());
  err_fid = fopen ('legend_18.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_19 ()
    
 clf;
 colormap (cool (64));
 surf (peaks ());
 legend ('peaks()');
 title ('legend() works for surface objects too');

end

try
  if (~ exist ('legend_19.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_19 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_19.png" ... ');
      tic ();
      print ('-dpng', 'legend_19.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_19.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_19: %s\n', lasterr ());
  err_fid = fopen ('legend_19.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_20 ()
    
 clf reset;  % needed to undo colormap assignment in previous demo
 rand_2x3_data2 = [0.44804, 0.84368, 0.23012; 0.72311, 0.58335, 0.90531];
 bar (rand_2x3_data2);
 ylim ([0 1.2]);
 title ('"left" option places colors to the left of text label');
 legend ('1st Bar', '2nd Bar', '3rd Bar');
 legend left;

end

try
  if (~ exist ('legend_20.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_20 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_20.png" ... ');
      tic ();
      print ('-dpng', 'legend_20.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_20.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_20: %s\n', lasterr ());
  err_fid = fopen ('legend_20.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_21 ()
    
 clf;
 x = 0:0.1:7;
 h = plot (x,sin(x), x,cos(x), x,sin(x.^2/10), x,cos(x.^2/10));
 title ('Only the sin() objects have keylabels');
 legend (h([1, 3]), {'sin (x)', 'sin (x^2/10)'}, 'location', 'southwest');

end

try
  if (~ exist ('legend_21.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_21 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_21.png" ... ');
      tic ();
      print ('-dpng', 'legend_21.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_21.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_21: %s\n', lasterr ());
  err_fid = fopen ('legend_21.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_22 ()
    
 clf;
 x = 0:0.1:10;
 plot (x, sin (x), ';sin (x);');
 hold on;
 plot (x, cos (x), ';cos (x);');
 hold off;
 title ('legend constructed from multiple plot calls');

end

try
  if (~ exist ('legend_22.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_22 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_22.png" ... ');
      tic ();
      print ('-dpng', 'legend_22.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_22.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_22: %s\n', lasterr ());
  err_fid = fopen ('legend_22.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_23 ()
    
 clf;
 x = 0:0.1:10;
 plot (x, sin (x), ';sin (x);');
 hold on;
 plot (x, cos (x), ';cos (x);');
 hold off;
 title ('Specified label text overrides previous labels');
 legend ({'Sine', 'Cosine'}, 'location', 'northeastoutside');

end

try
  if (~ exist ('legend_23.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_23 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_23.png" ... ');
      tic ();
      print ('-dpng', 'legend_23.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_23.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_23: %s\n', lasterr ());
  err_fid = fopen ('legend_23.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_24 ()
    
 clf;
 x = 0:10;
 plot (x, rand (11));
 axis ([0, 10, 0, 1]);
 xlabel ('Indices');
 ylabel ('Random Values');
 title ('Legend "off" deletes the legend');
 legend (cellstr (num2str ((0:10)')), 'location', 'northeastoutside');
 pause (1);
 legend off;

end

try
  if (~ exist ('legend_24.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_24 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_24.png" ... ');
      tic ();
      print ('-dpng', 'legend_24.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_24.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_24: %s\n', lasterr ());
  err_fid = fopen ('legend_24.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_25 ()
    
 clf;
 x = (1:5)';
 subplot (2,2,1);
  plot (x, rand (numel (x)));
  legend (cellstr (num2str (x)), 'location', 'northwestoutside');
 subplot (2,2,2);
  plot (x, rand (numel (x)));
  legend (cellstr (num2str (x)), 'location', 'northeastoutside');
 subplot (2,2,3);
  plot (x, rand (numel (x)));
  legend (cellstr (num2str (x)), 'location', 'southwestoutside');
 subplot (2,2,4);
  plot (x, rand (numel (x)));
  legend (cellstr (num2str (x)), 'location', 'southeastoutside');
 %% Legend works on a per axes basis for each subplot

end

try
  if (~ exist ('legend_25.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_25 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_25.png" ... ');
      tic ();
      print ('-dpng', 'legend_25.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_25.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_25: %s\n', lasterr ());
  err_fid = fopen ('legend_25.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_26 ()
    
 clf;
 plot (rand (2));
 title ('legend() will warn if extra labels are specified');
 legend ('Hello', 'World', 'interpreter', 'foobar');

end

try
  if (~ exist ('legend_26.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_26 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_26.png" ... ');
      tic ();
      print ('-dpng', 'legend_26.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_26.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_26: %s\n', lasterr ());
  err_fid = fopen ('legend_26.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_27 ()
    
 clf;
 x = 0:10;
 y1 = rand (size (x));
 y2 = rand (size (x));
 [ax, h1, h2] = plotyy (x, y1, x, y2);
 title ({'plotyy legend test %1', 'Blue label to left axis, Orange label to right axis'});
 drawnow ();
 legend ('Blue', 'Orange', 'location', 'south');

end

try
  if (~ exist ('legend_27.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_27 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_27.png" ... ');
      tic ();
      print ('-dpng', 'legend_27.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_27.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_27: %s\n', lasterr ());
  err_fid = fopen ('legend_27.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_28 ()
    
 clf;
 x = 0:10;
 y1 = rand (size (x));
 y2 = rand (size (x));
 [ax, h1, h2] = plotyy (x, y1, x, y2);
 ylabel (ax(1), {'Blue', 'Y', 'Axis'});
 title ('plotyy legend test #2: "westoutside" adjusts to ylabel');
 drawnow ();
 legend ([h1, h2], {'Blue', 'Orange'}, 'location', 'westoutside');

end

try
  if (~ exist ('legend_28.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_28 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_28.png" ... ');
      tic ();
      print ('-dpng', 'legend_28.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_28.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_28: %s\n', lasterr ());
  err_fid = fopen ('legend_28.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_29 ()
    
 clf;
 x = 0:10;
 y1 = rand (size (x));
 y2 = rand (size (x));
 [ax, h1, h2] = plotyy (x, y1, x, y2);
 ylabel (ax(2), {'Orange', 'Y', 'Axis'});
 title ('plotyy legend test #3: "eastoutside" adjusts to ylabel');
 drawnow ();
 legend ([h1, h2], {'Blue', 'Orange'}, 'location', 'eastoutside');

end

try
  if (~ exist ('legend_29.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_29 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_29.png" ... ');
      tic ();
      print ('-dpng', 'legend_29.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_29.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_29: %s\n', lasterr ());
  err_fid = fopen ('legend_29.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_30 ()
    
 clf;
 plot (1:10, 1:10);
 title ('a very long label can sometimes cause problems');
 legend ('hello very big world', 'location', 'northeastoutside');

end

try
  if (~ exist ('legend_30.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_30 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_30.png" ... ');
      tic ();
      print ('-dpng', 'legend_30.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_30.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_30: %s\n', lasterr ());
  err_fid = fopen ('legend_30.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_31 ()
      % bug 36408
 clf;
 option = 'right';
 subplot (3,1,1);
  plot (rand (1,4));
  xlabel xlabel;
  ylabel ylabel;
  title ('Subplots adjust to the legend placed outside');
  legend ({'1'}, 'location', 'northeastoutside');
  legend (option);
 subplot (3,1,2);
  plot (rand (1,4));
  xlabel xlabel;
  ylabel ylabel;
  legend ({'1234567890'}, 'location', 'eastoutside');
  legend (option);
 subplot (3,1,3);
  plot (rand (1,4));
  xlabel xlabel;
  ylabel ylabel;
  legend ({'12345678901234567890'}, 'location', 'southeastoutside');
  legend (option);

end

try
  if (~ exist ('legend_31.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_31 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_31.png" ... ');
      tic ();
      print ('-dpng', 'legend_31.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_31.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_31: %s\n', lasterr ());
  err_fid = fopen ('legend_31.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_32 ()
      % bug 36408
 clf;
 option = 'right';
 subplot (3,1,1);
  plot (rand (1,4));
  title ('Subplots adjust to the legend placed outside');
  legend ({'1'}, 'location', 'northwestoutside');
  legend (option);
 subplot (3,1,2);
  plot (rand (1,4));
  legend ({'1234567890'}, 'location', 'westoutside');
  legend (option);
 subplot (3,1,3);
  plot (rand (1,4));
  legend ({'12345678901234567890'}, 'location', 'southwestoutside');
  legend (option);

end

try
  if (~ exist ('legend_32.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_32 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_32.png" ... ');
      tic ();
      print ('-dpng', 'legend_32.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_32.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_32: %s\n', lasterr ());
  err_fid = fopen ('legend_32.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_33 ()
      % bug 36408
 clf;
 option = 'right';
 subplot (3,1,1);
  plot (rand (1,4));
  set (gca (), 'yaxislocation', 'right');
  xlabel ('xlabel');
  ylabel ('ylabel');
  title ('Subplots adjust to the legend placed outside');
  legend ({'1'}, 'location', 'northeastoutside');
  legend (option);
 subplot (3,1,2);
  plot (rand (1,4));
  set (gca (), 'yaxislocation', 'right');
  xlabel ('xlabel');
  ylabel ('ylabel');
  legend ({'1234567890'}, 'location', 'eastoutside');
  legend (option);
 subplot (3,1,3);
  plot (rand (1,4));
  set (gca (), 'yaxislocation', 'right');
  xlabel ('xlabel');
  ylabel ('ylabel');
  legend ({'12345678901234567890'}, 'location', 'southeastoutside');
  legend (option);

end

try
  if (~ exist ('legend_33.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_33 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_33.png" ... ');
      tic ();
      print ('-dpng', 'legend_33.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_33.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_33: %s\n', lasterr ());
  err_fid = fopen ('legend_33.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_34 ()
      % bug 36408
 clf;
 option = 'right';
 subplot (3,1,1);
  plot (rand (1,4));
  set (gca (), 'yaxislocation', 'right');
  xlabel ('xlabel');
  ylabel ('ylabel');
  title ('Subplots adjust to the legend placed outside');
  legend ({'1'}, 'location', 'northwestoutside');
  legend (option);
 subplot (3,1,2);
  plot (rand (1,4));
  set (gca (), 'yaxislocation', 'right');
  xlabel ('xlabel');
  ylabel ('ylabel');
  legend ({'1234567890'}, 'location', 'westoutside');
  legend (option);
 subplot (3,1,3);
  plot (rand (1,4));
  set (gca (), 'yaxislocation', 'right');
  xlabel ('xlabel');
  ylabel ('ylabel');
  legend ({'12345678901234567890'}, 'location', 'southwestoutside');
  legend (option);

end

try
  if (~ exist ('legend_34.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_34 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_34.png" ... ');
      tic ();
      print ('-dpng', 'legend_34.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_34.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_34: %s\n', lasterr ());
  err_fid = fopen ('legend_34.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_35 ()
      % bug 36408;
 clf;
 option = 'right';
 subplot (3,1,1);
  plot (rand (1,4));
  set (gca (), 'xaxislocation', 'top');
  xlabel ('xlabel');
  ylabel ('ylabel');
  title ('Subplots adjust to the legend placed outside');
  legend ({'1'}, 'location', 'northwestoutside');
  legend (option);
 subplot (3,1,2);
  plot (rand (1,4));
  set (gca (), 'xaxislocation', 'top');
  xlabel ('xlabel');
  ylabel ('ylabel');
  legend ({'1234567890'}, 'location', 'westoutside');
  legend (option);
 subplot (3,1,3);
  plot (rand (1,4));
  set (gca (), 'xaxislocation', 'top');
  xlabel ('xlabel');
  ylabel ('ylabel');
  legend ({'12345678901234567890'}, 'location', 'southwestoutside');
  legend (option);

end

try
  if (~ exist ('legend_35.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_35 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_35.png" ... ');
      tic ();
      print ('-dpng', 'legend_35.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_35.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_35: %s\n', lasterr ());
  err_fid = fopen ('legend_35.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function legend_36 ()
      % bug 39697
 clf;
 plot (1:10);
 legend ('Legend Text');
 title ({'Multi-line', 'titles', 'are a', 'problem', 'See bug #39697'});

end

try
  if (~ exist ('legend_36.png', 'file'))
    rand ('seed', 1);
    tic ();
    legend_36 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "legend_36.png" ... ');
      tic ();
      print ('-dpng', 'legend_36.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "legend_36.png" already exists.\n');
  end
catch
  fprintf ('ERROR in legend_36: %s\n', lasterr ());
  err_fid = fopen ('legend_36.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function lighting_01 ()
    
 clf;
 colormap ('default');
 sombrero ();
 shading flat
 lighting flat
 light ();
 title ('shading flat - lighting flat');

end

try
  if (~ exist ('lighting_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    lighting_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "lighting_01.png" ... ');
      tic ();
      print ('-dpng', 'lighting_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "lighting_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in lighting_01: %s\n', lasterr ());
  err_fid = fopen ('lighting_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function lighting_02 ()
    
 clf;
 colormap ('default');
 sombrero ();
 shading interp
 lighting gouraud
 light ();
 title ('shading interp - lighting gouraud');

end

try
  if (~ exist ('lighting_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    lighting_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "lighting_02.png" ... ');
      tic ();
      print ('-dpng', 'lighting_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "lighting_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in lighting_02: %s\n', lasterr ());
  err_fid = fopen ('lighting_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function lighting_03 ()
    
 clf;
 colormap ('default');
 pcolor (peaks ());
 shading flat
 lighting flat
 light ();
 view (3)
 title ('shading flat - lighting flat');

end

try
  if (~ exist ('lighting_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    lighting_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "lighting_03.png" ... ');
      tic ();
      print ('-dpng', 'lighting_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "lighting_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in lighting_03: %s\n', lasterr ());
  err_fid = fopen ('lighting_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function lighting_04 ()
    
 clf;
 colormap ('default');
 pcolor (peaks ());
 shading interp
 lighting gouraud
 light ();
 view (3)
 title ('shading interp - lighting gouraud');

end

try
  if (~ exist ('lighting_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    lighting_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "lighting_04.png" ... ');
      tic ();
      print ('-dpng', 'lighting_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "lighting_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in lighting_04: %s\n', lasterr ());
  err_fid = fopen ('lighting_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function lighting_05 ()
    
 clf;
 colormap ('default');
 mesh (sombrero ());
 shading flat
 lighting flat
 light ();
 title ('shading flat - lighting flat');

end

try
  if (~ exist ('lighting_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    lighting_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "lighting_05.png" ... ');
      tic ();
      print ('-dpng', 'lighting_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "lighting_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in lighting_05: %s\n', lasterr ());
  err_fid = fopen ('lighting_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function lighting_06 ()
    
 clf;
 colormap ('default');
 mesh (sombrero ());
 shading interp
 lighting gouraud
 light ();
 title ('shading interp - lighting gouraud');

end

try
  if (~ exist ('lighting_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    lighting_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "lighting_06.png" ... ');
      tic ();
      print ('-dpng', 'lighting_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "lighting_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in lighting_06: %s\n', lasterr ());
  err_fid = fopen ('lighting_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function material_01 ()
    
 clf;
 %% patch
 [x,y,z] = meshgrid (-2:0.2:2, -2:0.2:2, -2:0.2:2);
 val = x.^2 + y.^2 + z.^2;
 fv1 = isosurface (x, y, z, val, 1);
 h_patch = patch (fv1, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                       'FaceLighting', 'Gouraud');
 isonormals (x, y, z, val, h_patch);
 axis equal;  axis tight;
 view (3);
 box off;
 drawnow ();
 light ();
 material ([0 0.5 1 10 .5]);
 title ('material() with numeric input');

end

try
  if (~ exist ('material_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    material_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "material_01.png" ... ');
      tic ();
      print ('-dpng', 'material_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "material_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in material_01: %s\n', lasterr ());
  err_fid = fopen ('material_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function material_02 ()
    
 clf;
 %% surface
 hax = axes ();
 surf (hax, peaks, 'LineStyle', 'none', 'FaceLighting', 'Gouraud');
 view (3);
 light ();
 material metal;
 title ('material metal');

end

try
  if (~ exist ('material_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    material_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "material_02.png" ... ');
      tic ();
      print ('-dpng', 'material_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "material_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in material_02: %s\n', lasterr ());
  err_fid = fopen ('material_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pbaspect_01 ()
    
 clf;
 x = 0:0.01:4;
 plot (x,cos(x), x,sin(x));
 pbaspect ([1 1 1]);
 title ('plot box is square');

end

try
  if (~ exist ('pbaspect_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    pbaspect_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pbaspect_01.png" ... ');
      tic ();
      print ('-dpng', 'pbaspect_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pbaspect_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pbaspect_01: %s\n', lasterr ());
  err_fid = fopen ('pbaspect_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pbaspect_02 ()
    
 clf;
 x = 0:0.01:4;;
 plot (x,cos(x), x,sin(x));
 pbaspect ([2 1 1]);
 title ('plot box aspect ratio is 2x1');

end

try
  if (~ exist ('pbaspect_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    pbaspect_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pbaspect_02.png" ... ');
      tic ();
      print ('-dpng', 'pbaspect_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pbaspect_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pbaspect_02: %s\n', lasterr ());
  err_fid = fopen ('pbaspect_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pbaspect_03 ()
    
 clf;
 x = 0:0.01:4;
 plot (x,cos(x), x,sin(x));
 daspect ([1 1 1]);
 pbaspect ([2 1 1]);
 title ('plot box is 2x1, and axes [0 4 -1 1]');

end

try
  if (~ exist ('pbaspect_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    pbaspect_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pbaspect_03.png" ... ');
      tic ();
      print ('-dpng', 'pbaspect_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pbaspect_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pbaspect_03: %s\n', lasterr ());
  err_fid = fopen ('pbaspect_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_01 ()
    
 clf;
 colormap ('default');
 sombrero ();
 shading faceted;
 title ('shading ''faceted''');

end

try
  if (~ exist ('shading_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_01.png" ... ');
      tic ();
      print ('-dpng', 'shading_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_01: %s\n', lasterr ());
  err_fid = fopen ('shading_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_02 ()
    
 clf;
 colormap ('default');
 sombrero ();
 shading faceted;
 h = findobj (gca (), 'type', 'surface');
 facecolor = get (h, 'facecolor');
 edgecolor = get (h, 'edgecolor');
 set (h, 'edgecolor', facecolor, 'facecolor', edgecolor);
 title ({'shading ''faceted''', 'with "edgecolor" and "facecolor" reversed'});

end

try
  if (~ exist ('shading_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_02.png" ... ');
      tic ();
      print ('-dpng', 'shading_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_02: %s\n', lasterr ());
  err_fid = fopen ('shading_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_03 ()
    
 clf;
 colormap ('default');
 sombrero ();
 shading flat;
 title ('shading ''flat''');

end

try
  if (~ exist ('shading_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_03.png" ... ');
      tic ();
      print ('-dpng', 'shading_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_03: %s\n', lasterr ());
  err_fid = fopen ('shading_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_04 ()
    
 clf;
 colormap ('default');
 sombrero ();
 shading flat;
 h = findobj (gca (), 'type', 'surface');
 facecolor = get (h, 'facecolor');
 edgecolor = get (h, 'edgecolor');
 set (h, 'edgecolor', facecolor, 'facecolor', edgecolor);
 title ({'shading ''flat''', 'with "edgecolor" and "facecolor" reversed'});

end

try
  if (~ exist ('shading_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_04.png" ... ');
      tic ();
      print ('-dpng', 'shading_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_04: %s\n', lasterr ());
  err_fid = fopen ('shading_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_05 ()
    
 clf;
 colormap ('default');
 sombrero ();
 shading interp;
 title ('shading ''interp''');

end

try
  if (~ exist ('shading_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_05.png" ... ');
      tic ();
      print ('-dpng', 'shading_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_05: %s\n', lasterr ());
  err_fid = fopen ('shading_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_06 ()
    
 clf;
 colormap ('default');
 sombrero ();
 shading interp;
 h = findobj (gca (), 'type', 'surface');
 facecolor = get (h, 'facecolor');
 edgecolor = get (h, 'edgecolor');
 set (h, 'edgecolor', facecolor, 'facecolor', edgecolor);
 title ({'shading ''interp''', 'with "edgecolor" and "facecolor" reversed'});

end

try
  if (~ exist ('shading_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_06.png" ... ');
      tic ();
      print ('-dpng', 'shading_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_06: %s\n', lasterr ());
  err_fid = fopen ('shading_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_07 ()
    
 clf;
 colormap ('default');
 peaks ();
 shading interp;
 h = findobj (gca (), 'type', 'surface');
 set (h, 'edgecolor', 'k');
 title ({'shading ''interp''', 'with "edgecolor" set to black'});

end

try
  if (~ exist ('shading_07.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_07 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_07.png" ... ');
      tic ();
      print ('-dpng', 'shading_07.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_07.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_07: %s\n', lasterr ());
  err_fid = fopen ('shading_07.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_08 ()
    
 clf;
 colormap ('default');
 pcolor (peaks ());
 shading faceted;
 title ('shading ''faceted''');

end

try
  if (~ exist ('shading_08.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_08 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_08.png" ... ');
      tic ();
      print ('-dpng', 'shading_08.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_08.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_08: %s\n', lasterr ());
  err_fid = fopen ('shading_08.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_09 ()
    
 clf;
 colormap ('default');
 pcolor (peaks ());
 shading faceted;
 h = findobj (gca (), 'type', 'surface');
 facecolor = get (h, 'facecolor');
 edgecolor = get (h, 'edgecolor');
 set (h, 'edgecolor', facecolor, 'facecolor', edgecolor);
 title ({'shading ''faceted''', 'with "edgecolor" and "facecolor" reversed'});

end

try
  if (~ exist ('shading_09.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_09 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_09.png" ... ');
      tic ();
      print ('-dpng', 'shading_09.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_09.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_09: %s\n', lasterr ());
  err_fid = fopen ('shading_09.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_10 ()
    
 clf;
 colormap ('default');
 pcolor (peaks ());
 shading flat;
 title ('shading ''flat''');

end

try
  if (~ exist ('shading_10.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_10 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_10.png" ... ');
      tic ();
      print ('-dpng', 'shading_10.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_10.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_10: %s\n', lasterr ());
  err_fid = fopen ('shading_10.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_11 ()
    
 clf;
 colormap ('default');
 pcolor (peaks ());
 shading flat;
 h = findobj (gca (), 'type', 'surface');
 facecolor = get (h, 'facecolor');
 edgecolor = get (h, 'edgecolor');
 set (h, 'edgecolor', facecolor, 'facecolor', edgecolor);
 title ({'shading ''flat''', 'with "edgecolor" and "facecolor" reversed'});

end

try
  if (~ exist ('shading_11.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_11 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_11.png" ... ');
      tic ();
      print ('-dpng', 'shading_11.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_11.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_11: %s\n', lasterr ());
  err_fid = fopen ('shading_11.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_12 ()
    
 clf;
 colormap ('default');
 pcolor (peaks ());
 shading interp;
 title ('shading ''interp''');

end

try
  if (~ exist ('shading_12.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_12 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_12.png" ... ');
      tic ();
      print ('-dpng', 'shading_12.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_12.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_12: %s\n', lasterr ());
  err_fid = fopen ('shading_12.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_13 ()
    
 clf;
 colormap ('default');
 pcolor (peaks ());
 shading interp;
 h = findobj (gca (), 'type', 'surface');
 facecolor = get (h, 'facecolor');
 edgecolor = get (h, 'edgecolor');
 set (h, 'edgecolor', facecolor, 'facecolor', edgecolor);
 title ({'shading ''interp''', 'with "edgecolor" and "facecolor" reversed'});

end

try
  if (~ exist ('shading_13.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_13 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_13.png" ... ');
      tic ();
      print ('-dpng', 'shading_13.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_13.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_13: %s\n', lasterr ());
  err_fid = fopen ('shading_13.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_14 ()
    
 clf;
 colormap ('default');
 mesh (sombrero ());
 shading interp;
 title ('mesh with shading ''interp''');

end

try
  if (~ exist ('shading_14.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_14 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_14.png" ... ');
      tic ();
      print ('-dpng', 'shading_14.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_14.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_14: %s\n', lasterr ());
  err_fid = fopen ('shading_14.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shading_15 ()
    
 clf;
 colormap ('default');
 mesh (sombrero ());
 shading flat;
 title ('mesh with shading ''flat''');

end

try
  if (~ exist ('shading_15.png', 'file'))
    rand ('seed', 1);
    tic ();
    shading_15 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shading_15.png" ... ');
      tic ();
      print ('-dpng', 'shading_15.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shading_15.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shading_15: %s\n', lasterr ());
  err_fid = fopen ('shading_15.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function text_01 ()
    
 clf;
 ha = {'left', 'center', 'right'};
 va = {'bottom', 'middle', 'top'};
 x = [0.25 0.5 0.75];
 y = x;
 for t = 0:30:359;
   for nh = 1:numel (ha)
     for nv = 1:numel (va)
       text (x(nh), y(nv), 'Hello World', ...
             'rotation', t, ...
             'horizontalalignment', ha{nh}, ...
             'verticalalignment', va{nv});
     end
   end
 end
 set (gca, 'xtick', [0.25, 0.5, 0.75], ...
           'xticklabel', ha, ...
           'ytick', [0.25, 0.5, 0.75], ...
           'yticklabel', va);
 axis ([0 1 0 1]);
 xlabel ('horizontal alignment');
 ylabel ('vertical alignment');
 title ('text alignment and rotation (0:30:360 degrees)');

end

try
  if (~ exist ('text_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    text_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "text_01.png" ... ');
      tic ();
      print ('-dpng', 'text_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "text_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in text_01: %s\n', lasterr ());
  err_fid = fopen ('text_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function text_02 ()
    
 clf;
 h = mesh (peaks, 'edgecolor', 0.7 * [1 1 1], ...
                  'facecolor', 'none', ...
                  'facealpha', 0);
 colors = jet (9);
 ii = 1;
 for t = 0:45:359;
   ii = ii +1;
   text (25, 25, 0, 'Vertical Alignment = Bottom', ...
                    'rotation', t, ...
                    'horizontalalignment', 'left', ...
                    'backgroundcolor', colors(ii,:), ...
                    'edgecolor', 'k', ...
                    'verticalalignment', 'bottom');
 end
 caxis ([-100 100]);
 title ('Vertically Aligned at Bottom');

end

try
  if (~ exist ('text_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    text_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "text_02.png" ... ');
      tic ();
      print ('-dpng', 'text_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "text_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in text_02: %s\n', lasterr ());
  err_fid = fopen ('text_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function text_03 ()
    
 clf;
 axis ([0 8 0 8]);
 title (['1st title';'2nd title']);
 xlabel (['1st xlabel';'2nd xlabel']);
 ylabel (['1st ylabel';'2nd ylabel']);
 text (4, 4, {'Hello', 'World'}, ...
       'horizontalalignment', 'center', ...
       'verticalalignment', 'middle');
 grid on;

end

try
  if (~ exist ('text_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    text_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "text_03.png" ... ');
      tic ();
      print ('-dpng', 'text_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "text_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in text_03: %s\n', lasterr ());
  err_fid = fopen ('text_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function text_04 ()
    
 clf;
 h = mesh (peaks (), 'edgecolor', 0.7 * [1 1 1], ...
                     'facecolor', 'none', ...
                     'facealpha', 0);
 title (['1st title';'2nd title']);
 xlabel (['1st xlabel';'2nd xlabel']);
 ylabel (['1st ylabel';'2nd ylabel']);
 zlabel (['1st zlabel';'2nd zlabel']);
 text (0, 0, 5, {'Hello', 'World'}, ...
       'horizontalalignment', 'center', ...
       'verticalalignment', 'middle');
 hold on;
 plot3 (0, 0, 5, '+k');

end

try
  if (~ exist ('text_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    text_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "text_04.png" ... ');
      tic ();
      print ('-dpng', 'text_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "text_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in text_04: %s\n', lasterr ());
  err_fid = fopen ('text_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function text_05 ()
    
 clf;
 h = text (0.5, 0.3, 'char');
 h = text (0.5, 0.4, ['char row 1'; 'char row 2']);
 h = text (0.5, 0.6, {'cell2str (1,1)', 'cell2str (1,2)'; 'cell2str (2,1)', 'cell2str (2,2)'});
 h = text (0.5, 0.8, 'foobar');
 set (h, 'string', 1:3);
 h = text ([0.1, 0.1], [0.3, 0.4], 'one string & two objects');
 h = text ([0.1, 0.1], [0.5, 0.6], {'one cellstr & two objects'});
 h = text ([0.1, 0.1], [0.7, 0.8], {'cellstr 1 object 1', 'cellstr 2 object 2'});
 h = text ([0.1, 0.1], [0.1, 0.2], ['1st string & 1st object'; '2nd string & 2nd object']);
 h = text (0.7, 0.6, 'single string');
 h = text (0.7, 0.5, {'single cell-string'});
 xlabel (1:2);
 ylabel (1:2);
 title (1:2);

end

try
  if (~ exist ('text_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    text_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "text_05.png" ... ');
      tic ();
      print ('-dpng', 'text_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "text_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in text_05: %s\n', lasterr ());
  err_fid = fopen ('text_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function title_01 ()
    
 clf;
 title ('Test Title Text');

end

try
  if (~ exist ('title_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    title_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "title_01.png" ... ');
      tic ();
      print ('-dpng', 'title_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "title_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in title_01: %s\n', lasterr ());
  err_fid = fopen ('title_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function title_02 ()
    
 clf;
 title ({'Multi-line'; 'Title'; 'Text'});

end

try
  if (~ exist ('title_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    title_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "title_02.png" ... ');
      tic ();
      print ('-dpng', 'title_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "title_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in title_02: %s\n', lasterr ());
  err_fid = fopen ('title_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function title_03 ()
    
 clf;
 plot3 ([0,1], [0,1], [0,1]);
 title ('Test FontSize Property', 'fontsize', 16);

end

try
  if (~ exist ('title_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    title_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "title_03.png" ... ');
      tic ();
      print ('-dpng', 'title_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "title_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in title_03: %s\n', lasterr ());
  err_fid = fopen ('title_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function xlim_01 ()
    
 clf;
 line ();
 xlim ([0.2, 0.8]);
 title ('xlim is [0.2, 0.8]');

end

try
  if (~ exist ('xlim_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    xlim_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "xlim_01.png" ... ');
      tic ();
      print ('-dpng', 'xlim_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "xlim_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in xlim_01: %s\n', lasterr ());
  err_fid = fopen ('xlim_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function xlim_02 ()
    
 clf;
 line ();
 xlim auto;
 title ('xlim is auto');

end

try
  if (~ exist ('xlim_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    xlim_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "xlim_02.png" ... ');
      tic ();
      print ('-dpng', 'xlim_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "xlim_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in xlim_02: %s\n', lasterr ());
  err_fid = fopen ('xlim_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function xlim_03 ()
    
 clf;
 plot3 ([0,1], [0,1], [0,1]);
 xlim ([0.2, 0.8]);
 title ('xlim is [0.2, 0.8]');

end

try
  if (~ exist ('xlim_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    xlim_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "xlim_03.png" ... ');
      tic ();
      print ('-dpng', 'xlim_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "xlim_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in xlim_03: %s\n', lasterr ());
  err_fid = fopen ('xlim_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function xlim_04 ()
    
 clf;
 plot3 ([0,1], [0,1], [0,1]);
 xlim ('auto');
 title ('xlim is auto');

end

try
  if (~ exist ('xlim_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    xlim_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "xlim_04.png" ... ');
      tic ();
      print ('-dpng', 'xlim_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "xlim_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in xlim_04: %s\n', lasterr ());
  err_fid = fopen ('xlim_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ylim_01 ()
    
 clf;
 line ();
 ylim ([0.2, 0.8]);
 title ('ylim is [0.2, 0.8]');

end

try
  if (~ exist ('ylim_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ylim_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ylim_01.png" ... ');
      tic ();
      print ('-dpng', 'ylim_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ylim_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ylim_01: %s\n', lasterr ());
  err_fid = fopen ('ylim_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ylim_02 ()
    
 clf;
 line ();
 ylim auto;
 title ('ylim is auto');

end

try
  if (~ exist ('ylim_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    ylim_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ylim_02.png" ... ');
      tic ();
      print ('-dpng', 'ylim_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ylim_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ylim_02: %s\n', lasterr ());
  err_fid = fopen ('ylim_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ylim_03 ()
    
 clf;
 plot3 ([0,1], [0,1], [0,1]);
 ylim ([0.2, 0.8]);
 title ('ylim is [0.2, 0.8]');

end

try
  if (~ exist ('ylim_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    ylim_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ylim_03.png" ... ');
      tic ();
      print ('-dpng', 'ylim_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ylim_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ylim_03: %s\n', lasterr ());
  err_fid = fopen ('ylim_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ylim_04 ()
    
 clf;
 plot3 ([0,1], [0,1], [0,1]);
 ylim ('auto');
 title ('ylim is auto');

end

try
  if (~ exist ('ylim_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    ylim_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ylim_04.png" ... ');
      tic ();
      print ('-dpng', 'ylim_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ylim_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ylim_04: %s\n', lasterr ());
  err_fid = fopen ('ylim_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function zlim_01 ()
    
 clf;
 line ();
 zlim ([0.2, 0.8]);
 title ('zlim is [0.2, 0.8]');

end

try
  if (~ exist ('zlim_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    zlim_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "zlim_01.png" ... ');
      tic ();
      print ('-dpng', 'zlim_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "zlim_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in zlim_01: %s\n', lasterr ());
  err_fid = fopen ('zlim_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function zlim_02 ()
    
 clf;
 line ();
 zlim ('auto');
 title ('zlim is auto');

end

try
  if (~ exist ('zlim_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    zlim_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "zlim_02.png" ... ');
      tic ();
      print ('-dpng', 'zlim_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "zlim_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in zlim_02: %s\n', lasterr ());
  err_fid = fopen ('zlim_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function zlim_03 ()
    
 clf;
 plot3 ([0,1], [0,1], [0,1]);
 zlim ([0.2, 0.8]);
 title ('zlim is [0.2, 0.8]');

end

try
  if (~ exist ('zlim_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    zlim_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "zlim_03.png" ... ');
      tic ();
      print ('-dpng', 'zlim_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "zlim_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in zlim_03: %s\n', lasterr ());
  err_fid = fopen ('zlim_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function zlim_04 ()
    
 clf;
 plot3 ([0,1], [0,1], [0,1]);
 zlim auto;
 title ('zlim is auto');

end

try
  if (~ exist ('zlim_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    zlim_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "zlim_04.png" ... ');
      tic ();
      print ('-dpng', 'zlim_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "zlim_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in zlim_04: %s\n', lasterr ());
  err_fid = fopen ('zlim_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

close all

function area_01 ()
    
 %% Verify identity sin^2 + cos^2 = 1
 clf;
 t = linspace (0, 2*pi, 100)';
 y = [sin(t).^2, cos(t).^2];
 area (t, y);
 axis tight
 legend ('sin^2', 'cos^2', 'location', 'NorthEastOutside');
 title ('area() plot');

end

try
  if (~ exist ('area_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    area_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "area_01.png" ... ');
      tic ();
      print ('-dpng', 'area_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "area_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in area_01: %s\n', lasterr ());
  err_fid = fopen ('area_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function area_02 ()
    
 %% Show effects of setting BaseValue
 clf;
 x = [-2:0.1:2]';
 y = x.^2 - 1;
 subplot (1, 2, 1)
  area (x, y);
  title ({'Parabola y = x^2 -1';'BaseValue = 0'});
 subplot (1, 2, 2)
  h = area (x, y);
  set (h, 'basevalue', -1);
  title ({'Parabola y = x^2 -1';'BaseValue = -1'});

end

try
  if (~ exist ('area_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    area_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "area_02.png" ... ');
      tic ();
      print ('-dpng', 'area_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "area_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in area_02: %s\n', lasterr ());
  err_fid = fopen ('area_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function area_03 ()
    
 clf;
 x = 0:10;
 y = rand (size (x));
 h = area (x, y);
 set (h, 'ydata', sort (get (h, 'ydata')));
 title ('area() plot of sorted data');

end

try
  if (~ exist ('area_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    area_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "area_03.png" ... ');
      tic ();
      print ('-dpng', 'area_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "area_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in area_03: %s\n', lasterr ());
  err_fid = fopen ('area_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function bar_01 ()
    
 clf;
 y = rand (11, 1);
 h = bar (y);
 set (h, 'ydata', sort (rand (11, 1)));
 title ('bar() graph');

end

try
  if (~ exist ('bar_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    bar_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "bar_01.png" ... ');
      tic ();
      print ('-dpng', 'bar_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "bar_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in bar_01: %s\n', lasterr ());
  err_fid = fopen ('bar_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function bar_02 ()
    
 clf;
 h = bar (rand (5, 3));
 set (h(1), 'facecolor', 'r');
 set (h(2), 'facecolor', 'g');
 set (h(3), 'facecolor', 'b');
 title ('bar() graph w/multiple bars');

end

try
  if (~ exist ('bar_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    bar_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "bar_02.png" ... ');
      tic ();
      print ('-dpng', 'bar_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "bar_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in bar_02: %s\n', lasterr ());
  err_fid = fopen ('bar_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function bar_03 ()
    
 clf;
 h = bar (rand (5, 3), 'stacked');
 title ('bar() graph with stacked style');

end

try
  if (~ exist ('bar_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    bar_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "bar_03.png" ... ');
      tic ();
      print ('-dpng', 'bar_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "bar_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in bar_03: %s\n', lasterr ());
  err_fid = fopen ('bar_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function barh_01 ()
    
 clf;
 x = rand (10, 1);
 barh (x);
 title ('barh() graph');

end

try
  if (~ exist ('barh_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    barh_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "barh_01.png" ... ');
      tic ();
      print ('-dpng', 'barh_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "barh_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in barh_01: %s\n', lasterr ());
  err_fid = fopen ('barh_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function barh_02 ()
    
 clf;
 h = barh (rand (5, 3));
 set (h(1), 'facecolor', 'r');
 set (h(2), 'facecolor', 'g');
 set (h(3), 'facecolor', 'b');
 title ('barh() graph w/multiple bars');

end

try
  if (~ exist ('barh_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    barh_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "barh_02.png" ... ');
      tic ();
      print ('-dpng', 'barh_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "barh_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in barh_02: %s\n', lasterr ());
  err_fid = fopen ('barh_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function camlight_01 ()
    
 clf;
 %% Adding lights to a scene
 sphere (64);
 camlight

 %% Add a second light
 camlight left

 title ({'camlight()', 'lights are left and right'});

end

try
  if (~ exist ('camlight_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    camlight_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "camlight_01.png" ... ');
      tic ();
      print ('-dpng', 'camlight_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "camlight_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in camlight_01: %s\n', lasterr ());
  err_fid = fopen ('camlight_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function camlight_02 ()
    
 clf;
 sphere (48);
 title ({'camlight()', 'light in fixed position ignores camera change'});
 axis equal;
 shading flat;
 view (30, 30);

 camlight

 for a = 30:2:390
   view (a, 30);
   drawnow ();
   pause (0.01);
 end

end

try
  if (~ exist ('camlight_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    camlight_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "camlight_02.png" ... ');
      tic ();
      print ('-dpng', 'camlight_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "camlight_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in camlight_02: %s\n', lasterr ());
  err_fid = fopen ('camlight_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function camlight_03 ()
    
 clf;
 sphere (48);
 title ({'camlight()', 'update light position with camera change'});
 axis equal;  shading flat
 view (30, 30);

 hl = camlight ();          % keep a handle to the light

 for a = 30:2:390
   view (a, 30);
   camlight (hl, 'right');  % update light position
   drawnow ();
   pause (0.01);
 end

end

try
  if (~ exist ('camlight_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    camlight_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "camlight_03.png" ... ');
      tic ();
      print ('-dpng', 'camlight_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "camlight_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in camlight_03: %s\n', lasterr ());
  err_fid = fopen ('camlight_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_01 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 imagesc (x);
 colorbar ();
 title ('colorbar() example');

end

try
  if (~ exist ('colorbar_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_01.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_01: %s\n', lasterr ());
  err_fid = fopen ('colorbar_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_02 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 imagesc (x);
 colorbar ('westoutside');

end

try
  if (~ exist ('colorbar_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_02.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_02: %s\n', lasterr ());
  err_fid = fopen ('colorbar_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_03 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 imagesc (x);
 colorbar ('peer', gca, 'northoutside');

end

try
  if (~ exist ('colorbar_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_03.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_03: %s\n', lasterr ());
  err_fid = fopen ('colorbar_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_04 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 imagesc (x);
 colorbar ('southoutside');

end

try
  if (~ exist ('colorbar_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_04.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_04: %s\n', lasterr ());
  err_fid = fopen ('colorbar_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_05 ()
    
 clf;
 colormap ('default');
 contour (peaks ());
 colorbar ('west');

end

try
  if (~ exist ('colorbar_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_05.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_05: %s\n', lasterr ());
  err_fid = fopen ('colorbar_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_06 ()
    
 clf;
 colormap ('default');
 subplot (2,2,1);
  contour (peaks ());
  colorbar ('east');
 subplot (2,2,2);
  contour (peaks ());
  colorbar ('west');
 subplot (2,2,3);
  contour (peaks ());
  colorbar ('north');
 subplot (2,2,4);
  contour (peaks ());
  colorbar ('south');

end

try
  if (~ exist ('colorbar_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_06.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_06: %s\n', lasterr ());
  err_fid = fopen ('colorbar_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_07 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (2,2,1);
  imagesc (x);
  colorbar ();
 subplot (2,2,2);
  imagesc (x);
  colorbar ('westoutside');
 subplot (2,2,3);
  imagesc (x);
  colorbar ('northoutside');
 subplot (2,2,4);
  imagesc (x);
  colorbar ('southoutside');

end

try
  if (~ exist ('colorbar_07.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_07 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_07.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_07.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_07.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_07: %s\n', lasterr ());
  err_fid = fopen ('colorbar_07.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_08 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (1,2,1);
  imagesc (x);
  axis square;
  colorbar ();
 subplot (1,2,2);
  imagesc (x);
  axis square;
  colorbar ('westoutside');

end

try
  if (~ exist ('colorbar_08.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_08 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_08.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_08.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_08.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_08: %s\n', lasterr ());
  err_fid = fopen ('colorbar_08.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_09 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (1,2,1);
  imagesc (x);
  axis square;
  colorbar ('northoutside');
 subplot (1,2,2);
  imagesc (x);
  axis square;
  colorbar ('southoutside');

end

try
  if (~ exist ('colorbar_09.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_09 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_09.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_09.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_09.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_09: %s\n', lasterr ());
  err_fid = fopen ('colorbar_09.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_10 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (2,1,1);
  imagesc (x);
  axis square;
  colorbar ();
 subplot (2,1,2);
  imagesc (x);
  axis square;
  colorbar ('westoutside');

end

try
  if (~ exist ('colorbar_10.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_10 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_10.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_10.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_10.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_10: %s\n', lasterr ());
  err_fid = fopen ('colorbar_10.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_11 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (2,1,1);
  imagesc (x);
  axis square;
  colorbar ('northoutside');
 subplot (2,1,2);
  imagesc (x);
  axis square;
  colorbar ('southoutside');

end

try
  if (~ exist ('colorbar_11.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_11 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_11.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_11.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_11.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_11: %s\n', lasterr ());
  err_fid = fopen ('colorbar_11.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_12 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (1,2,1);
  imagesc (x);
  colorbar ();
 subplot (1,2,2);
  imagesc (x);
  colorbar ('westoutside');

end

try
  if (~ exist ('colorbar_12.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_12 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_12.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_12.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_12.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_12: %s\n', lasterr ());
  err_fid = fopen ('colorbar_12.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_13 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (1,2,1);
  imagesc (x);
  colorbar ('northoutside');
 subplot (1,2,2);
  imagesc (x);
  colorbar ('southoutside');

end

try
  if (~ exist ('colorbar_13.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_13 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_13.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_13.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_13.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_13: %s\n', lasterr ());
  err_fid = fopen ('colorbar_13.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_14 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (2,1,1);
  imagesc (x);
  colorbar ();
 subplot (2,1,2);
  imagesc (x);
  colorbar ('westoutside');

end

try
  if (~ exist ('colorbar_14.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_14 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_14.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_14.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_14.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_14: %s\n', lasterr ());
  err_fid = fopen ('colorbar_14.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_15 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (2,1,1);
  imagesc (x);
  colorbar ('northoutside');
 subplot (2,1,2);
  imagesc (x);
  colorbar ('southoutside');

end

try
  if (~ exist ('colorbar_15.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_15 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_15.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_15.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_15.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_15: %s\n', lasterr ());
  err_fid = fopen ('colorbar_15.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_16 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 subplot (1,2,1);
  contour (x);
  axis square;
  colorbar ('east');
  xlim ([1, 64]);
  ylim ([1, 64]);
 subplot (1,2,2);
  contour (x);
  colorbar ('west');
  xlim ([1, 64]);
  ylim ([1, 64]);

end

try
  if (~ exist ('colorbar_16.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_16 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_16.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_16.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_16.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_16: %s\n', lasterr ());
  err_fid = fopen ('colorbar_16.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_17 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 contour (x);
 xlim ([1, 64]);
 ylim ([1, 64]);
 colorbar ();
 colorbar off;
 title ('colorbar off');

end

try
  if (~ exist ('colorbar_17.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_17 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_17.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_17.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_17.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_17: %s\n', lasterr ());
  err_fid = fopen ('colorbar_17.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_18 ()
    
 clf;
 colormap ('default');
 n = 64; x = kron (1:n, ones (n,1)); x = abs (x - x.');
 contour (x);
 xlim ([1, 64]);
 ylim ([1, 64]);
 colorbar ();

end

try
  if (~ exist ('colorbar_18.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_18 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_18.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_18.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_18.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_18: %s\n', lasterr ());
  err_fid = fopen ('colorbar_18.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_19 ()
    
 clf;
 colormap ('default');
 imagesc (log10 (1 ./ hilb (99)));
 h = colorbar ();
 ytick = get (h, 'ytick');
 set (h, 'yticklabel', sprintf ('10^{%g}|', ytick));

end

try
  if (~ exist ('colorbar_19.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_19 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_19.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_19.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_19.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_19: %s\n', lasterr ());
  err_fid = fopen ('colorbar_19.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_20 ()
    
 clf;
 colormap ('default');
 n = 5; x = linspace (0,5,n); y = linspace (0,1,n);
 imagesc (1 ./ hilb (n));
 axis equal;
 colorbar ();

end

try
  if (~ exist ('colorbar_20.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_20 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_20.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_20.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_20.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_20: %s\n', lasterr ());
  err_fid = fopen ('colorbar_20.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_21 ()
    
 clf;
 colormap ('default');
 n = 5; x = linspace (0,5,n); y = linspace (0,1,n);
 imagesc (x, y, 1 ./ hilb (n));
 axis equal;
 colorbar ();

end

try
  if (~ exist ('colorbar_21.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_21 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_21.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_21.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_21.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_21: %s\n', lasterr ());
  err_fid = fopen ('colorbar_21.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_22 ()
    
 clf;
 colormap ('default');
 n = 5; x = linspace (0,5,n); y = linspace (0,1,n);
 imagesc (y, x, 1 ./ hilb (n));
 axis equal;
 colorbar ();

end

try
  if (~ exist ('colorbar_22.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_22 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_22.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_22.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_22.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_22: %s\n', lasterr ());
  err_fid = fopen ('colorbar_22.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_23 ()
    
 clf;
 colormap ('default');
 axes;
 colorbar ();
 hold on;
 contour (peaks ());
 hold off;

end

try
  if (~ exist ('colorbar_23.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_23 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_23.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_23.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_23.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_23: %s\n', lasterr ());
  err_fid = fopen ('colorbar_23.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_24 ()
    
 clf;
 colormap ('default');
 plot ([0, 2]);
 colorbar ('east');
 axis square;

end

try
  if (~ exist ('colorbar_24.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_24 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_24.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_24.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_24.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_24: %s\n', lasterr ());
  err_fid = fopen ('colorbar_24.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_25 ()
    
 clf;
 colormap ('default');
 plot ([0, 2]);
 colorbar ('eastoutside');
 axis square;

end

try
  if (~ exist ('colorbar_25.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_25 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_25.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_25.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_25.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_25: %s\n', lasterr ());
  err_fid = fopen ('colorbar_25.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_26 ()
    
 clf;
 colormap ('default');
 pcolor (peaks (20));
 shading interp;
 axis ('tight', 'square');
 colorbar ();

end

try
  if (~ exist ('colorbar_26.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_26 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_26.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_26.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_26.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_26: %s\n', lasterr ());
  err_fid = fopen ('colorbar_26.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_27 ()
    
 clf;
 colormap ('default');
 plot ([0, 2]);
 colorbar ('east');
 axis equal;

end

try
  if (~ exist ('colorbar_27.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_27 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_27.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_27.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_27.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_27: %s\n', lasterr ());
  err_fid = fopen ('colorbar_27.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorbar_28 ()
    
 clf;
 colormap ('default');
 plot ([0, 2]);
 colorbar ('eastoutside');
 axis equal;

end

try
  if (~ exist ('colorbar_28.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorbar_28 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorbar_28.png" ... ');
      tic ();
      print ('-dpng', 'colorbar_28.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorbar_28.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorbar_28: %s\n', lasterr ());
  err_fid = fopen ('colorbar_28.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function comet_01 ()
    
 clf;
 title ('comet() animation');
 hold on;
 t = 0:.1:2*pi;
 x = cos (2*t) .* (cos (t).^2);
 y = sin (2*t) .* (sin (t).^2);
 comet (x, y, 0.05);
 hold off;

end

try
  if (~ exist ('comet_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    comet_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "comet_01.png" ... ');
      tic ();
      print ('-dpng', 'comet_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "comet_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in comet_01: %s\n', lasterr ());
  err_fid = fopen ('comet_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function comet3_01 ()
    
 clf;
 title ('comet3() animation');
 view (3); hold on;
 t = 0:pi/20:5*pi;
 comet3 (cos (t), sin (t), t, 0.05);
 hold off;

end

try
  if (~ exist ('comet3_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    comet3_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "comet3_01.png" ... ');
      tic ();
      print ('-dpng', 'comet3_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "comet3_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in comet3_01: %s\n', lasterr ());
  err_fid = fopen ('comet3_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function compass_01 ()
    
 clf;
 randn_9x1_data = [-2.555884; 0.394974; -0.191871; -1.147024; 1.355425; -0.437335; -0.014370; -0.941312; 1.240300];
 randn_1x9_data = [1.42934, -1.10821, -1.70404, 0.63357, -0.68337, -1.19771, -0.96502, -1.12810, 0.22457];
 a = toeplitz ([1;randn_9x1_data], [1,randn_1x9_data]);
 compass (eig (a));
 title ('compass() example');

end

try
  if (~ exist ('compass_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    compass_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "compass_01.png" ... ');
      tic ();
      print ('-dpng', 'compass_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "compass_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in compass_01: %s\n', lasterr ());
  err_fid = fopen ('compass_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function contour_01 ()
    
 clf;
 colormap ('default');
 [x, y, z] = peaks ();
 contour (x, y, z);
 title ({'contour() plot (isolines of constant Z)'; 'Z = peaks()'});

end

try
  if (~ exist ('contour_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    contour_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "contour_01.png" ... ');
      tic ();
      print ('-dpng', 'contour_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "contour_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in contour_01: %s\n', lasterr ());
  err_fid = fopen ('contour_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function contour_02 ()
    
 clf;
 colormap ('default');
 [theta, r] = meshgrid (linspace (0,2*pi,64), linspace (0,1,64));
 [X, Y] = pol2cart (theta, r);
 Z = sin (2*theta) .* (1-r);
 contour (X, Y, abs (Z), 10);
 title ({'contour() plot'; 'polar fcn: Z = sin (2*theta) * (1-r)'});

end

try
  if (~ exist ('contour_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    contour_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "contour_02.png" ... ');
      tic ();
      print ('-dpng', 'contour_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "contour_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in contour_02: %s\n', lasterr ());
  err_fid = fopen ('contour_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function contour_03 ()
    
 clf;
 colormap ('default');
 z = peaks ();
 contour (z, [0 0]);
 title ({'contour() plot with single isoline at Z == 0'; 'Z = peaks()'});

end

try
  if (~ exist ('contour_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    contour_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "contour_03.png" ... ');
      tic ();
      print ('-dpng', 'contour_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "contour_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in contour_03: %s\n', lasterr ());
  err_fid = fopen ('contour_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function contour3_01 ()
    
 clf;
 colormap (cool (64));
 surf (peaks (19), 'facecolor', 'none', 'edgecolor', [0.85 0.85 0.85]);
 hold on;
 contour3 (peaks (19));
 hold off;
 axis tight;
 zlim auto;
 view (315, 17);
 title ({'contour3 of peaks() function', 'gray surf() shows peaks function'});

end

try
  if (~ exist ('contour3_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    contour3_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "contour3_01.png" ... ');
      tic ();
      print ('-dpng', 'contour3_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "contour3_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in contour3_01: %s\n', lasterr ());
  err_fid = fopen ('contour3_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function contourf_01 ()
    
 clf;
 colormap ('default');
 [x, y, z] = peaks (50);
 contourf (x, y, z, -7:9);
 title ({'contourf() plot (filled contour lines)'; 'Z = peaks()'});

end

try
  if (~ exist ('contourf_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    contourf_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "contourf_01.png" ... ');
      tic ();
      print ('-dpng', 'contourf_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "contourf_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in contourf_01: %s\n', lasterr ());
  err_fid = fopen ('contourf_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function contourf_02 ()
    
 clf;
 colormap ('default');
 [theta, r] = meshgrid (linspace (0,2*pi,64), linspace (0,1,64));
 [X, Y] = pol2cart (theta, r);
 Z = sin (2*theta) .* (1-r);
 contourf (X, Y, abs (Z), 10);
 title ({'contourf() plot'; 'polar fcn: Z = sin (2*theta) * (1-r)'});

end

try
  if (~ exist ('contourf_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    contourf_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "contourf_02.png" ... ');
      tic ();
      print ('-dpng', 'contourf_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "contourf_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in contourf_02: %s\n', lasterr ());
  err_fid = fopen ('contourf_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function contourf_03 ()
    
 clf;
 colormap ('default');
 x = linspace (-2, 2);
 [x, y] = meshgrid (x);
 z = sqrt (x.^2 + y.^2) ./ (x.^2 + y.^2 + 1);
 contourf (x, y, z, [0.4, 0.4]);
 title ('Hole should be filled with the background color');

end

try
  if (~ exist ('contourf_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    contourf_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "contourf_03.png" ... ');
      tic ();
      print ('-dpng', 'contourf_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "contourf_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in contourf_03: %s\n', lasterr ());
  err_fid = fopen ('contourf_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function cylinder_01 ()
    
 clf;
 colormap ('default');
 [x, y, z] = cylinder (10:-1:0, 50);
 surf (x, y, z);
 title ('cylinder() with linearly shrinking radius produces a cone');

end

try
  if (~ exist ('cylinder_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    cylinder_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "cylinder_01.png" ... ');
      tic ();
      print ('-dpng', 'cylinder_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "cylinder_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in cylinder_01: %s\n', lasterr ());
  err_fid = fopen ('cylinder_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ellipsoid_01 ()
    
 clf;
 ellipsoid (0, 0, 1, 2, 3, 4, 20);
 title ('ellipsoid()');

end

try
  if (~ exist ('ellipsoid_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ellipsoid_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ellipsoid_01.png" ... ');
      tic ();
      print ('-dpng', 'ellipsoid_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ellipsoid_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ellipsoid_01: %s\n', lasterr ());
  err_fid = fopen ('ellipsoid_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function errorbar_01 ()
    
 clf;
 rand_1x11_data1 = [0.82712, 0.50325, 0.35613, 0.77089, 0.20474, 0.69160, 0.30858, 0.88225, 0.35187, 0.14168, 0.54270];
 rand_1x11_data2 = [0.506375, 0.330106, 0.017982, 0.859270, 0.140641, 0.327839, 0.275886, 0.162453, 0.807592, 0.318509, 0.921112];
 errorbar (0:10, rand_1x11_data1, 0.25*rand_1x11_data2);
 title ('errorbar() with Y errorbars');

end

try
  if (~ exist ('errorbar_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    errorbar_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "errorbar_01.png" ... ');
      tic ();
      print ('-dpng', 'errorbar_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "errorbar_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in errorbar_01: %s\n', lasterr ());
  err_fid = fopen ('errorbar_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function errorbar_02 ()
    
 clf;
 rand_1x11_data3 = [0.423650, 0.142331, 0.213195, 0.129301, 0.975891, 0.012872, 0.635327, 0.338829, 0.764997, 0.401798, 0.551850];
 rand_1x11_data4 = [0.682566, 0.456342, 0.132390, 0.341292, 0.108633, 0.601553, 0.040455, 0.146665, 0.309187, 0.586291, 0.540149];
 errorbar (0:10, rand_1x11_data3, rand_1x11_data4, '>');
 title ('errorbar() with X errorbars');

end

try
  if (~ exist ('errorbar_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    errorbar_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "errorbar_02.png" ... ');
      tic ();
      print ('-dpng', 'errorbar_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "errorbar_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in errorbar_02: %s\n', lasterr ());
  err_fid = fopen ('errorbar_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function errorbar_03 ()
    
 clf;
 x = 0:0.5:2*pi;
 err = x/30;
 y1 = sin (x);
 y2 = cos (x);
 errorbar (x, y1, err, '~', x, y2, err, '>');
 legend ('Y errbar', 'X errbar');
 title ('errorbar() with 2 datasets');

end

try
  if (~ exist ('errorbar_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    errorbar_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "errorbar_03.png" ... ');
      tic ();
      print ('-dpng', 'errorbar_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "errorbar_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in errorbar_03: %s\n', lasterr ());
  err_fid = fopen ('errorbar_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function errorbar_04 ()
    
 clf;
 x = 0:0.5:2*pi;
 err = x/30;
 y1 = sin (x);
 y2 = cos (x);
 errorbar (x, y1, err, err, '#r', x, y2, err, err, '#~');
 legend ('X errbox', 'Y errbox');
 title ('errorbar() with error boxes');

end

try
  if (~ exist ('errorbar_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    errorbar_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "errorbar_04.png" ... ');
      tic ();
      print ('-dpng', 'errorbar_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "errorbar_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in errorbar_04: %s\n', lasterr ());
  err_fid = fopen ('errorbar_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function errorbar_05 ()
    
 clf;
 x = 0:0.5:2*pi;
 err = x/30;
 y1 = sin (x);
 y2 = cos (x);
 errorbar (x, y1, err, err, err, err, '~>', ...
           x, y2, err, err, err, err, '#~>-*');
 legend ('X-Y errbars', 'X-Y errboxes');
 title ('errorbar() with X-Y errorbars and error boxes');

end

try
  if (~ exist ('errorbar_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    errorbar_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "errorbar_05.png" ... ');
      tic ();
      print ('-dpng', 'errorbar_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "errorbar_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in errorbar_05: %s\n', lasterr ());
  err_fid = fopen ('errorbar_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezcontour_01 ()
    
 clf;
 colormap ('default');
 f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2);
 ezcontour (f, [-3, 3]);

end

try
  if (~ exist ('ezcontour_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezcontour_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezcontour_01.png" ... ');
      tic ();
      print ('-dpng', 'ezcontour_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezcontour_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezcontour_01: %s\n', lasterr ());
  err_fid = fopen ('ezcontour_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezcontourf_01 ()
    
 clf;
 colormap ('default');
 f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2);
 ezcontourf (f, [-3, 3]);

end

try
  if (~ exist ('ezcontourf_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezcontourf_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezcontourf_01.png" ... ');
      tic ();
      print ('-dpng', 'ezcontourf_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezcontourf_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezcontourf_01: %s\n', lasterr ());
  err_fid = fopen ('ezcontourf_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezmesh_01 ()
    
 clf;
 colormap ('default');
 f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2);
 ezmesh (f, [-3, 3]);

end

try
  if (~ exist ('ezmesh_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezmesh_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezmesh_01.png" ... ');
      tic ();
      print ('-dpng', 'ezmesh_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezmesh_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezmesh_01: %s\n', lasterr ());
  err_fid = fopen ('ezmesh_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezmesh_02 ()
    
 clf;
 colormap ('default');
 fx = @(s,t) cos (s) .* cos (t);
 fy = @(s,t) sin (s) .* cos (t);
 fz = @(s,t) sin (t);
 ezmesh (fx, fy, fz, [-pi,pi,-pi/2,pi/2], 20);

end

try
  if (~ exist ('ezmesh_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezmesh_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezmesh_02.png" ... ');
      tic ();
      print ('-dpng', 'ezmesh_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezmesh_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezmesh_02: %s\n', lasterr ());
  err_fid = fopen ('ezmesh_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezmeshc_01 ()
    
 clf;
 colormap ('default');
 f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2);
 ezmeshc (f, [-3, 3]);

end

try
  if (~ exist ('ezmeshc_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezmeshc_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezmeshc_01.png" ... ');
      tic ();
      print ('-dpng', 'ezmeshc_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezmeshc_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezmeshc_01: %s\n', lasterr ());
  err_fid = fopen ('ezmeshc_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezplot_01 ()
    
 %% sinc function using function handle
 clf;
 f = @(x) sin (pi*x) ./ (pi*x);
 ezplot (f);

end

try
  if (~ exist ('ezplot_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezplot_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezplot_01.png" ... ');
      tic ();
      print ('-dpng', 'ezplot_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezplot_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezplot_01: %s\n', lasterr ());
  err_fid = fopen ('ezplot_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezplot_02 ()
    
 %% example of a function string and explicit limits
 clf;
 ezplot ('1/x', [-2 2]);

end

try
  if (~ exist ('ezplot_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezplot_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezplot_02.png" ... ');
      tic ();
      print ('-dpng', 'ezplot_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezplot_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezplot_02: %s\n', lasterr ());
  err_fid = fopen ('ezplot_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezplot_03 ()
    
 %% parameterized function example over -2*pi <= t <= +2*pi
 clf;
 ezplot (@cos, @sin);

end

try
  if (~ exist ('ezplot_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezplot_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezplot_03.png" ... ');
      tic ();
      print ('-dpng', 'ezplot_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezplot_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezplot_03: %s\n', lasterr ());
  err_fid = fopen ('ezplot_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezplot_04 ()
    
 %% implicit function of 2 variables
 clf;
 ezplot (inline ('x^2 - y^2 - 1'));

end

try
  if (~ exist ('ezplot_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezplot_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezplot_04.png" ... ');
      tic ();
      print ('-dpng', 'ezplot_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezplot_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezplot_04: %s\n', lasterr ());
  err_fid = fopen ('ezplot_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezplot3_01 ()
    
 clf;
 fx = @(t) cos (t);
 fy = @(t) sin (t);
 fz = @(t) t;
 ezplot3 (fx, fy, fz, [0, 10*pi], 100);

end

try
  if (~ exist ('ezplot3_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezplot3_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezplot3_01.png" ... ');
      tic ();
      print ('-dpng', 'ezplot3_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezplot3_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezplot3_01: %s\n', lasterr ());
  err_fid = fopen ('ezplot3_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezplot3_02 ()
    
 clf;
 fx = @(t) cos (t);
 fy = @(t) sin (t);
 fz = @(t) t;
 ezplot3 (fx, fy, fz, [0, 5*pi], 100, 'animate');

end

try
  if (~ exist ('ezplot3_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezplot3_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezplot3_02.png" ... ');
      tic ();
      print ('-dpng', 'ezplot3_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezplot3_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezplot3_02: %s\n', lasterr ());
  err_fid = fopen ('ezplot3_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezpolar_01 ()
    
 clf;
 ezpolar (@(t) sin (5/4 * t), [0, 8*pi]);

end

try
  if (~ exist ('ezpolar_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezpolar_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezpolar_01.png" ... ');
      tic ();
      print ('-dpng', 'ezpolar_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezpolar_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezpolar_01: %s\n', lasterr ());
  err_fid = fopen ('ezpolar_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezsurf_01 ()
    
 clf;
 colormap ('default');
 f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2);
 ezsurf (f, [-3, 3]);

end

try
  if (~ exist ('ezsurf_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezsurf_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezsurf_01.png" ... ');
      tic ();
      print ('-dpng', 'ezsurf_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezsurf_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezsurf_01: %s\n', lasterr ());
  err_fid = fopen ('ezsurf_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezsurf_02 ()
    
 clf;
 colormap ('default');
 fx = @(s,t) cos (s) .* cos (t);
 fy = @(s,t) sin (s) .* cos (t);
 fz = @(s,t) sin (t);
 ezsurf (fx, fy, fz, [-pi,pi,-pi/2,pi/2], 20);
 axis equal;

end

try
  if (~ exist ('ezsurf_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezsurf_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezsurf_02.png" ... ');
      tic ();
      print ('-dpng', 'ezsurf_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezsurf_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezsurf_02: %s\n', lasterr ());
  err_fid = fopen ('ezsurf_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezsurf_03 ()
    
 clf;
 colormap ('default');
 f = @(x,y) x.^2 + y.^2;
 subplot (1,2,1);
  ezsurf (f, [-2,2]);
  title ({'x^2 + y^2'; 'plotted over rectangular grid (default)'});
 subplot (1,2,2);
  ezsurf (f, [-2,2], 'circ');
  title ({'x^2 + y^2'; 'plotted over circular disk with "circ"'});

end

try
  if (~ exist ('ezsurf_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezsurf_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezsurf_03.png" ... ');
      tic ();
      print ('-dpng', 'ezsurf_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezsurf_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezsurf_03: %s\n', lasterr ());
  err_fid = fopen ('ezsurf_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ezsurfc_01 ()
    
 clf;
 colormap ('default');
 f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2);
 ezsurfc (f, [-3, 3]);

end

try
  if (~ exist ('ezsurfc_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ezsurfc_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ezsurfc_01.png" ... ');
      tic ();
      print ('-dpng', 'ezsurfc_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ezsurfc_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ezsurfc_01: %s\n', lasterr ());
  err_fid = fopen ('ezsurfc_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function feather_01 ()
    
 clf;
 phi = [0 : 15 : 360] * pi/180;
 feather (sin (phi), cos (phi));
 axis tight;
 title ('feather plot');

end

try
  if (~ exist ('feather_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    feather_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "feather_01.png" ... ');
      tic ();
      print ('-dpng', 'feather_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "feather_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in feather_01: %s\n', lasterr ());
  err_fid = fopen ('feather_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function fill_01 ()
    
 clf;
 t1 = (1/16:1/8:1) * 2*pi;
 t2 = ((1/16:1/8:1) + 1/32) * 2*pi;
 x1 = sin (t1) - 0.8;
 y1 = cos (t1);
 x2 = sin (t2) + 0.8;
 y2 = cos (t2);
 h = fill (x1,y1,'r', x2,y2,'g');
 title ({'fill() function'; 'cdata specified with string'});

end

try
  if (~ exist ('fill_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    fill_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "fill_01.png" ... ');
      tic ();
      print ('-dpng', 'fill_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "fill_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in fill_01: %s\n', lasterr ());
  err_fid = fopen ('fill_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function fill_02 ()
    
 clf;
 t1 = (1/16:1/8:1) * 2*pi;
 t2 = ((1/16:1/8:1) + 1/32) * 2*pi;
 x1 = sin (t1) - 0.8;
 y1 = cos (t1);
 x2 = sin (t2) + 0.8;
 y2 = cos (t2);
 h = fill (x1,y1,1, x2,y2,2);
 title ({'fill() function'; 'cdata = row vector produces FaceColor = "flat"'});

end

try
  if (~ exist ('fill_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    fill_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "fill_02.png" ... ');
      tic ();
      print ('-dpng', 'fill_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "fill_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in fill_02: %s\n', lasterr ());
  err_fid = fopen ('fill_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function fill_03 ()
    
 clf;
 x = [0 0
      1 0.5
      1 0.5
      0 0];
 y = [0 0
      0 0
      1 0.5
      1 0.5];
 c = [1 2 3 4]';
 fill (x, y, [c c]);
 title ({'fill() function'; 'cdata = column vector produces FaceColor = "interp"'});

end

try
  if (~ exist ('fill_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    fill_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "fill_03.png" ... ');
      tic ();
      print ('-dpng', 'fill_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "fill_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in fill_03: %s\n', lasterr ());
  err_fid = fopen ('fill_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function fplot_01 ()
    
 clf;
 fplot (@cos, [0, 2*pi]);
 title ('fplot() single function');

end

try
  if (~ exist ('fplot_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    fplot_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "fplot_01.png" ... ');
      tic ();
      print ('-dpng', 'fplot_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "fplot_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in fplot_01: %s\n', lasterr ());
  err_fid = fopen ('fplot_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function fplot_02 ()
    
 clf;
 fplot ('[cos(x), sin(x)]', [0, 2*pi]);
 title ('fplot() multiple functions');

end

try
  if (~ exist ('fplot_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    fplot_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "fplot_02.png" ... ');
      tic ();
      print ('-dpng', 'fplot_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "fplot_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in fplot_02: %s\n', lasterr ());
  err_fid = fopen ('fplot_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function fplot_03 ()
    
 clf;
 fh = @(x) sin (pi*x) ./ (pi*x);
 fplot (fh, [-5, 5]);
 title ('fplot() sinc function (possible division by 0, near 0)');

end

try
  if (~ exist ('fplot_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    fplot_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "fplot_03.png" ... ');
      tic ();
      print ('-dpng', 'fplot_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "fplot_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in fplot_03: %s\n', lasterr ());
  err_fid = fopen ('fplot_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function isocaps_01 ()
    
 clf;
 isoval = .4;
 lin = linspace (0, 1.2, 15);
 [x, y, z] = meshgrid (lin, lin, lin);
 v = abs ((x-.45).^2 + (y-.55).^2 + (z-.8).^2);
 hf = clf;
 ha = axes;
 view (3);  box off;
 fvc_iso = isosurface (x, y, z, v, isoval);
 cmap = get (hf, 'Colormap');
 p_iso = patch (fvc_iso, 'FaceLighting', 'gouraud', ...
                'FaceColor', cmap(end,:), 'EdgeColor', 'none');
 isonormals (x, y, z, v, p_iso);
 fvc_xmin = isocaps (x, y, z, v, isoval, 'xmin', 'b');
 patch (fvc_xmin, 'FaceColor', 'interp', 'EdgeColor', 'none', ...
        'FaceLighting', 'gouraud', ...
        'VertexNormals', repmat([-1 0 0], size (fvc_xmin.vertices, 1), 1));
 fvc_ymin = isocaps (x, y, z, v, isoval, 'ymin', 'b');
 patch (fvc_ymin, 'FaceColor', 'interp', 'EdgeColor', 'none', ...
        'FaceLighting', 'gouraud', ...
        'VertexNormals', repmat([0 -1 0], size (fvc_ymin.vertices, 1), 1));
 fvc_zmax = isocaps (x, y, z, v, isoval, 'zmax', 'b');
 patch (fvc_zmax, 'FaceColor', 'interp', 'EdgeColor', 'none', ...
        'FaceLighting', 'gouraud', ...
        'VertexNormals', repmat([0 -1 0], size (fvc_zmax.vertices, 1), 1));
 axis equal;
 light ();
 title ({'isocaps()', 'sphere with 6 end-caps'});

end

try
  if (~ exist ('isocaps_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    isocaps_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "isocaps_01.png" ... ');
      tic ();
      print ('-dpng', 'isocaps_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "isocaps_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in isocaps_01: %s\n', lasterr ());
  err_fid = fopen ('isocaps_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function isocaps_02 ()
    
 clf;
 v = smooth3 (rand (6, 8, 4));
 isoval = .5;
 x = 1:3:22;  y = -14:5:11;  z = linspace (16, 18, 4);
 [xx, yy, zz] = meshgrid (x, y, z);
 clf;
 %% two arguments, no output
 subplot (2, 2, 1);
  isocaps (v, isoval);
  view (3);
 %% five arguments, no output (x, y, z are vectors)
 subplot (2, 2, 2);
  isocaps (x, y, z, v, isoval);
  view (3);
 %% five arguments, no output (x, y, z are matrices)
 subplot (2, 2, 3);
  isocaps (xx, yy, zz, v, isoval);
  view (3);
 %% five arguments, no output (mixed x, y, z)
 subplot (2, 2, 4);
  isocaps (x, yy, z, v, isoval);
  view (3);

 annotation ('textbox', [0.41 0.9 0.9 0.1], ...
     'String', 'isocaps() called 4 ways', ...
     'HorizontalAlignment', 'center', ...
     'FontSize', 12);
 annotation ('textbox', [0.1 0.47 0.9 0.1], ...
     'String', ['Apart from the first plot having a different scale, ' ...
     'all four plots must look the same.'], ...
     'HorizontalAlignment', 'left', ...
     'FontSize', 12);

end

try
  if (~ exist ('isocaps_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    isocaps_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "isocaps_02.png" ... ');
      tic ();
      print ('-dpng', 'isocaps_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "isocaps_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in isocaps_02: %s\n', lasterr ());
  err_fid = fopen ('isocaps_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function isocolors_01 ()
    
 function isofinish (p)
   set (gca, 'PlotBoxAspectRatioMode', 'manual', ...
             'PlotBoxAspectRatio', [1 1 1]);
   set (p, 'FaceColor', 'interp');
   set (p, 'FaceLighting', 'flat');
   light ('Position', [1 1 5]);
 end

 N = 15;    % Increase number of vertices in each direction
 iso = .4;  % Change isovalue to .1 to display a sphere
 lin = linspace (0, 2, N);
 [x, y, z] = meshgrid (lin, lin, lin);
 c = abs ((x-.5).^2 + (y-.5).^2 + (z-.5).^2);
 clf;

 subplot (2,2,1);
  view (-38, 20);
  [f, v] = isosurface (x, y, z, c, iso);
  p = patch ('Faces', f, 'Vertices', v, 'EdgeColor', 'none');
  cdat = rand (size (c));       % Compute random color data
  isocolors (x, y, z, cdat, p); % Directly set colors of patch
  title ('random colors for patch handle');
  isofinish (p);

 subplot (2,2,2);
  view (-38, 20);
  p = patch ('Faces', f, 'Vertices', v, 'EdgeColor', 'none');
  [r, g, b] = meshgrid (lin, 2-lin, 2-lin);
  cdat = isocolors (x, y, z, c, v); % Compute color data vertices
  set (p, 'FaceVertexCData', cdat); % Set color data manually
  title ('random colors for "FaceVertexCData"');
  isofinish (p);

 subplot (2,2,3);
  view (-38, 20);
  p = patch ('Faces', f, 'Vertices', v, 'EdgeColor', 'none');
  cdat = isocolors (r, g, b, c, p); % Compute color data for patch
  set (p, 'FaceVertexCData', cdat); % Set color data manually
  title ('random RGB colors for "FaceVertexCData"');
  isofinish (p);

 subplot (2,2,4);
  view (-38, 20);
  p = patch ('Faces', f, 'Vertices', v, 'EdgeColor', 'none');
r = repmat ([1:N] / N, [N, 1, N]); % Black to white
g = repmat ([1:N] / N, [N, 1, N]); % Black to white
b = repmat ([1:N] / N, [N, 1, N]); % Black to white
  cdat = isocolors (x, y, z, r, g, b, v);
  set (p, 'FaceVertexCData', cdat);
  title ('gray shades for "FaceVertexCData"');
  isofinish (p);

end

try
  if (~ exist ('isocolors_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    isocolors_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "isocolors_01.png" ... ');
      tic ();
      print ('-dpng', 'isocolors_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "isocolors_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in isocolors_01: %s\n', lasterr ());
  err_fid = fopen ('isocolors_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function isonormals_01 ()
    
 function isofinish (hp)
   axis equal;
   set (hp, 'VertexNormals', -get (hp, 'VertexNormals'));  % Revert normals
   shading interp;
   lighting gouraud;
   set (hp, 'BackFaceLighting', 'lit');
   light ();
 end

 N = 15;    % Increase number of vertices in each direction
 iso = .4;  % Change isovalue to .1 to display a sphere
 lin = linspace (0, 2, N);
 [x, y, z] = meshgrid (lin, lin, lin);
 val = (x-.5).^2 + (y-.5).^2 + (z-.5).^2;
 clf;

 subplot (2,2,1);
  view (-38, 20);
  [fac, vert, cdat] = isosurface (x, y, z, val, iso, y);
  hp = patch ('Faces', fac, 'Vertices', vert, 'FaceVertexCData', cdat);
  title ('without isonormals');
  isofinish (hp);
  set (hp, 'VertexNormalsMode', 'auto');  % for Matlab compatibility

 subplot (2,2,2);
  view (-38, 20);
  hp = patch ('Faces', fac, 'Vertices', vert, 'FaceVertexCData', cdat);
  title ('patch modified by isonormals');
  isonormals (x, y, z, val, hp);  % Directly modify patch
  isofinish (hp);

 subplot (2,2,3);
  view (-38, 20);
  hp = patch ('Faces', fac, 'Vertices', vert, 'FaceVertexCData', cdat);
  vn = isonormals (x, y, z, val, vert);  % Compute normals of isosurface
  set (hp, 'VertexNormals', vn);         % Manually set vertex normals
  title ('set "VertexNormals" from isonormals');
  isofinish (hp);

 subplot (2,2,4);
  view (-38, 20);
  hp = patch ('Faces', fac, 'Vertices', vert, 'FaceVertexCData', cdat);
  isonormals (x, y, z, val, hp, 'negate');  % Use reverse directly
  title ('patch modified by isonormals (..., "negate")');
  isofinish (hp);

end

try
  if (~ exist ('isonormals_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    isonormals_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "isonormals_01.png" ... ');
      tic ();
      print ('-dpng', 'isonormals_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "isonormals_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in isonormals_01: %s\n', lasterr ());
  err_fid = fopen ('isonormals_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function isosurface_01 ()
    
 clf;
 [x,y,z] = meshgrid (-2:0.5:2, -2:0.5:2, -2:0.5:2);
 v = x.^2 + y.^2 + z.^2;
 isosurface (x, y, z, v, 1);
 axis equal;
 title ('isosurface() of a sphere');

end

try
  if (~ exist ('isosurface_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    isosurface_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "isosurface_01.png" ... ');
      tic ();
      print ('-dpng', 'isosurface_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "isosurface_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in isosurface_01: %s\n', lasterr ());
  err_fid = fopen ('isosurface_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function isosurface_02 ()
    
 clf;
 [x,y,z] = meshgrid (-2:0.5:2, -2:0.5:2, -2:0.5:2);
 v = x.^2 + y.^2 + z.^2;
 isosurface (x, y, z, v, 3);
 isosurface (x, y, z, v, 5);
 axis equal;
 title ('isosurface() of two nested spheres');

end

try
  if (~ exist ('isosurface_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    isosurface_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "isosurface_02.png" ... ');
      tic ();
      print ('-dpng', 'isosurface_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "isosurface_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in isosurface_02: %s\n', lasterr ());
  err_fid = fopen ('isosurface_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function isosurface_03 ()
    
 clf;
 x = 0:2;
 y = 0:3;
 z = 0:1;
 [xx, yy, zz] = meshgrid (x, y, z);
 v        = [0, 0, 0; 0, 0, 0; 0, 0, 1; 0, 0, 1];
 v(:,:,2) = [0, 0, 0; 0, 0, 1; 0, 1, 2; 0, 1, 2];
 iso = 0.8;

 %% Three arguments, no output
 subplot (2, 2, 1);
  fvc = isosurface (v, iso, yy);
  patch (fvc);
  shading faceted;
  view (110, 40);
 %% six arguments, no output (x, y, z are vectors)
 subplot (2, 2, 2);
  fvc = isosurface (x, y, z, v, iso, yy);
  patch (fvc);
  shading faceted;
  view (110, 40);
 %% six arguments, no output (x, y, z are matrices)
 subplot (2, 2, 3);
  fvc = isosurface (xx, yy, zz, v, iso, yy);
  patch (fvc);
  shading faceted;
  view (110, 40);
 %% six arguments, no output (mixed x, y, z) and option 'noshare'
 subplot (2, 2, 4);
  fvc = isosurface (x, yy, z, v, iso, yy, 'noshare');
  patch (fvc);
  shading faceted;
  view (110, 40);
  annotation ('textbox', [0.41 0.9 0.9 0.1], ...
      'String', 'isosurface() called 4 ways', ...
      'HorizontalAlignment', 'center', ...
      'FontSize', 12);
  annotation ('textbox', [0.1 0.45 0.9 0.1], ...
      'String', {['Apart from the first plot having a different scale, ' ...
                  'all four plots must look the same.'],
                 ['The last plot might have different colors but must ' ...
                  'have the same shape.']}, ...
      'HorizontalAlignment', 'left', ...
      'FontSize', 12);

end

try
  if (~ exist ('isosurface_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    isosurface_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "isosurface_03.png" ... ');
      tic ();
      print ('-dpng', 'isosurface_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "isosurface_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in isosurface_03: %s\n', lasterr ());
  err_fid = fopen ('isosurface_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_01 ()
    
 %% Demonstrate effects of lighting
 clf;
 %% patches
 h_axes1 = subplot (2, 2, 1);
  [x,y,z] = meshgrid (-2:0.2:2, -2:0.2:2, -2:0.2:2);
  val = x.^2 + y.^2 + z.^2;
  fv1 = isosurface (x, y, z, val, 1);
  h_patch1 = patch (fv1, 'FaceColor', 'c', 'EdgeColor', 'none', ...
                         'FaceLighting', 'Gouraud');
  isonormals (x, y, z, val, h_patch1);
  fv2 = isosurface (x, y+3, z, val, 1);
  h_patch2 = patch (fv2, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                         'FaceLighting', 'Gouraud');
  isonormals (x, y+3, z, val, h_patch2);
  view (3);
  axis equal;  axis tight;
  title ('Patch with lighting');
  h_light1 = light ();

 h_axes2 = subplot (2, 2, 2);
  patch (fv1, 'FaceColor', 'c', 'EdgeColor', 'none');
  patch (fv2, 'FaceColor', 'r', 'EdgeColor', 'none');
  view (3);
  axis equal;  axis tight;
  title ('Patch without lighting');

 %% surfaces
 h_axes3 = subplot (2, 2, 3);
  h_surf1 = surf (h_axes3, peaks, 'LineStyle', 'none', ...
                                  'FaceLighting', 'Gouraud');
  title ('Surface with lighting');
  view (3);
  h_light2 = light ();

 h_axes3 = subplot (2, 2, 4);
  h_surf2 = surf (h_axes3, peaks, 'LineStyle', 'none');
  view (3);
  title ('Surface without lighting');

end

try
  if (~ exist ('light_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_01.png" ... ');
      tic ();
      print ('-dpng', 'light_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_01: %s\n', lasterr ());
  err_fid = fopen ('light_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_02 ()
    
 %% Lighting modes
 clf;
 [x,y,z] = meshgrid (-.2:0.05:.2, -.2:0.05:.2, -.2:0.05:.2);
 val = (x.^2 + y.^2 + z.^2);

 h_axes1 = axes ();
 fv = isosurface (x, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'none');
 isonormals (x, y, z, val, h_patch);
 fv = isosurface (x+.5, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'flat');
 isonormals (x+.5, y, z, val, h_patch)
 fv = isosurface (x+1, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 isonormals (x+1, y, z, val, h_patch);
 axis tight
 axis equal
 view (2);
 light ('Position', [-1 1 1]);
 title ({'FaceLighting', 'none - flat - gouraud'});

end

try
  if (~ exist ('light_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_02.png" ... ');
      tic ();
      print ('-dpng', 'light_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_02: %s\n', lasterr ());
  err_fid = fopen ('light_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_03 ()
    
 %% multiple lights
 clf;
 h_axes = subplot (1, 2, 1);
  [x,y,z] = meshgrid (-2:0.1:2, -2:0.1:2, -2:0.1:2);
  val = x.^2 + y.^2 + z.^2;
  fv = isosurface (x, y, z, val, 1);
  h_patch = patch (fv, 'FaceColor', 'w', 'EdgeColor', 'none', ...
                       'FaceLighting', 'Gouraud');
  isonormals (x, y, z, val, h_patch);
  view (3);
  axis equal;  axis tight;
  title ('Patch with one light');
  h_light = light ('Color', 'g');

 h_axes2 = subplot (1, 2, 2);
  h_patch2 = patch (fv, 'FaceColor', 'w', 'EdgeColor', 'none', ...
                        'FaceLighting', 'Gouraud');
  isonormals (x, y, z, val, h_patch2);
  view (3);
  axis equal;  axis tight;
  title ('Patch with three lights');
  h_light1 = light ('Color', 'r');
  h_light2 = light ('Position', [0 1 1], 'Color', 'b');
  h_light3 = light ('Position', [-1 -1 2], 'Color', 'g');

end

try
  if (~ exist ('light_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_03.png" ... ');
      tic ();
      print ('-dpng', 'light_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_03: %s\n', lasterr ());
  err_fid = fopen ('light_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_04 ()
    
 %% Diffuse and specular reflection
 clf;
 h_axes = axes ();
 [x,y,z] = meshgrid (-.2:0.04:.2, -.2:0.04:.2, -.2:0.04:.2);
 val = (x.^2 + y.^2 + z.^2);

 fv = isosurface (x, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'DiffuseStrength', 0, 'SpecularStrength', 0);
 isonormals (x, y, z, val, h_patch);
 fv = isosurface (x+.5, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'DiffuseStrength', 0, 'SpecularStrength', .5);
 isonormals (x+.5, y, z, val, h_patch);
 fv = isosurface (x+1, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'DiffuseStrength', 0, 'SpecularStrength', 1);
 isonormals (x+1, y, z, val, h_patch);

 fv = isosurface (x, y+.5, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'DiffuseStrength', 0.5, 'SpecularStrength', 0);
 isonormals (x, y+.5, z, val, h_patch);
 fv = isosurface (x+.5, y+.5, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'DiffuseStrength', 0.5, 'SpecularStrength', .5);
 isonormals (x+.5, y+.5, z, val, h_patch);
 fv = isosurface (x+1, y+.5, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'DiffuseStrength', 0.5, 'SpecularStrength', 1);
 isonormals (x+1, y+.5, z, val, h_patch);

 fv = isosurface (x, y+1, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'DiffuseStrength', 1, 'SpecularStrength', 0);
 isonormals (x, y+1, z, val, h_patch);
 fv = isosurface (x+.5, y+1, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'DiffuseStrength', 1, 'SpecularStrength', .5);
 isonormals (x+.5, y+1, z, val, h_patch);
 fv = isosurface (x+1, y+1, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'DiffuseStrength', 1, 'SpecularStrength', 1);
 isonormals (x+1, y+1, z, val, h_patch);

 view (2);
 axis equal
 h_light = light ('Position', [-1 1 1]);

 xlabel ('SpecularStrength');
 ylabel ('DiffuseStrength');
 title ('Effects of SpecularStrength and DiffuseStrength');

end

try
  if (~ exist ('light_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_04.png" ... ');
      tic ();
      print ('-dpng', 'light_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_04: %s\n', lasterr ());
  err_fid = fopen ('light_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_05 ()
    
 %% Ambient Strength and Ambient Light Color
 clf;
 [x,y,z] = meshgrid (-.2:0.05:.2, -.2:0.05:.2, -.2:0.05:.2);
 val = (x.^2 + y.^2 + z.^2);

 h_axes1 = subplot (3,1,3);
  set (h_axes1, 'AmbientLightColor', 'g');
  fv = isosurface (x, y, z, val, .039);
  h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                       'FaceLighting', 'Gouraud');
  set (h_patch, 'AmbientStrength', 0);
  isonormals (x, y, z, val, h_patch);
  fv = isosurface (x+.5, y, z, val, .039);
  h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                       'FaceLighting', 'Gouraud');
  set (h_patch, 'AmbientStrength', .7);
  isonormals (x+.5, y, z, val, h_patch);
  fv = isosurface (x+1, y, z, val, .039);
  h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                       'FaceLighting', 'Gouraud');
  set (h_patch, 'AmbientStrength', 1);
  isonormals (x+1, y, z, val, h_patch);
  h_light = light ('Position', [-1 1 1]);
  view (2);
  axis tight
  axis equal
  xlabel ('AmbientStrength');
  ylabel ({'AmbientLightColor', '[0 1 0]'});

 h_axes2 = subplot (3,1,2);
  set (h_axes2, 'AmbientLightColor', [.5 0 1]);
  fv = isosurface (x, y, z, val, .039);
  h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                       'FaceLighting', 'Gouraud');
  set (h_patch, 'AmbientStrength', 0);
  isonormals (x, y, z, val, h_patch);
  fv = isosurface (x+.5, y, z, val, .039);
  h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                       'FaceLighting', 'Gouraud');
  set (h_patch, 'AmbientStrength', .7);
  isonormals (x+.5, y, z, val, h_patch);
  fv = isosurface (x+1, y, z, val, .039);
  h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                       'FaceLighting', 'Gouraud');
  set (h_patch, 'AmbientStrength', 1);
  isonormals (x+1, y, z, val, h_patch);
  h_light = light ('Position', [-1 1 1]);
  view (2);
  axis tight
  axis equal
  ylabel ({'AmbientLightColor', '[.5 0 1]'});

 h_axes3 = subplot (3,1,1);
  set (h_axes3, 'AmbientLightColor', 'w');
  fv = isosurface (x, y, z, val, .039);
  h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                       'FaceLighting', 'Gouraud');
  set (h_patch, 'AmbientStrength', 0);
  isonormals (x, y, z, val, h_patch);
  fv = isosurface (x+.5, y, z, val, .039);
  h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                       'FaceLighting', 'Gouraud');
  set (h_patch, 'AmbientStrength', .7);
  isonormals (x+.5, y, z, val, h_patch);
  fv = isosurface (x+1, y, z, val, .039);
  h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                       'FaceLighting', 'Gouraud');
  set (h_patch, 'AmbientStrength', 1);
  isonormals (x+1, y, z, val, h_patch);
  h_light = light ('Position', [-1 1 1]);
  view (2);
  axis tight
  axis equal
  ylabel ({'AmbientLightColor', '[1 1 1]'});
  title ('Effects of AmbientLightColor and AmbientStrength');

end

try
  if (~ exist ('light_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_05.png" ... ');
      tic ();
      print ('-dpng', 'light_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_05: %s\n', lasterr ());
  err_fid = fopen ('light_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_06 ()
    
 %% Specular Exponent
 clf;
 [x,y,z] = meshgrid (-.2:0.02:.2, -.2:0.02:.2, -.2:0.02:.2);
 val = (x.^2 + y.^2 + z.^2);

 h_axes = axes ();
 fv = isosurface (x, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'SpecularExponent', 15);
 isonormals (x, y, z, val, h_patch);
 fv = isosurface (x+.5, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'SpecularExponent', 5);
 isonormals (x+.5, y, z, val, h_patch);
 fv = isosurface (x+1, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'SpecularExponent', 1);
 isonormals (x+1, y, z, val, h_patch);
 h_light = light ('Position', [-1 1 1]);
 view (2);
 axis tight
 axis equal
 xlabel ('SpecularExponent');
 title ('Effects of SpecularExponent');

end

try
  if (~ exist ('light_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_06.png" ... ');
      tic ();
      print ('-dpng', 'light_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_06: %s\n', lasterr ());
  err_fid = fopen ('light_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_07 ()
    
 %% SpecularColorReflectance
 clf;
 [x,y,z] = meshgrid (-.2:0.02:.2, -.2:0.02:.2, -.2:0.02:.2);
 val = (x.^2 + y.^2 + z.^2);

 h_axes = axes ();
 fv = isosurface (x, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'SpecularColorReflectance', 0);
 isonormals (x, y, z, val, h_patch);
 fv = isosurface (x+.5, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'SpecularColorReflectance', 0.5);
 isonormals (x+.5, y, z, val, h_patch);
 fv = isosurface (x+1, y, z, val, .039);
 h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'SpecularColorReflectance', 1);
 isonormals (x+1, y, z, val, h_patch);
 view (2);
 h_light = light ('Position', [-1 1 1]);
 axis tight
 axis equal
 xlabel ('SpecularColorReflectance');
 title ('Effects of SpecularColorReflectance');

end

try
  if (~ exist ('light_07.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_07 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_07.png" ... ');
      tic ();
      print ('-dpng', 'light_07.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_07.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_07: %s\n', lasterr ());
  err_fid = fopen ('light_07.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_08 ()
    
 %% BackFaceLighting
 clf;
 [x,y,z] = meshgrid (-.5:0.1:2, -2:0.1:2, -2:0.1:2);
 val = x.^2 + y.^2 + z.^2;
 fv = isosurface (x, y, z, val, 1);
 vn = isonormals (x, y, z, val, fv.vertices);
 h_axes1 = subplot (1, 3, 1);
 h_patch = patch (fv, 'FaceColor', 'c', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud', 'VertexNormals', vn);
 set (h_patch, 'BackFaceLighting', 'reverselit');
 h_light = light ();
 view (h_axes1, [-50 30]);
 title ('reverselit');
 axis equal

 h_axes2 = subplot (1, 3, 2);
 h_patch = patch (fv, 'FaceColor', 'c', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud', 'VertexNormals', -vn);
 set (h_patch, 'BackFaceLighting', 'lit');
 h_light = light ();
 view (h_axes2, [-50 30]);
 axis equal
 title ('lit');

 h_axes3 = subplot (1, 3, 3);
 h_patch = patch (fv, 'FaceColor', 'c', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud', 'VertexNormals', -vn);
 set (h_patch, 'BackFaceLighting', 'unlit');
 h_light = light ();
 view (h_axes3, [-50 30]);
 axis equal
 title ('unlit');

end

try
  if (~ exist ('light_08.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_08 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_08.png" ... ');
      tic ();
      print ('-dpng', 'light_08.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_08.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_08: %s\n', lasterr ());
  err_fid = fopen ('light_08.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_09 ()
    
 %% BackFaceLighting 2
 %% Matlab fails for 'reverselit' with negated isonormals and for 'unlit'
 clf;
 N = 30; iso = .8;
 lin = linspace (-1, 1, N);
 [x, y, z] = meshgrid (1.2*lin, 1.2*lin, lin);
 val = (x).^2 + (y).^2 - iso/2.7*cos (2*pi*z);
 val(x>0 & (y-x)>0) = NaN;
 fv = isosurface (x, y, z, val, iso);
 vn = isonormals (x, y, z, val, fv.vertices);

 subplot (2, 3, 1);
  view (140, 20);
  axis equal
  hp = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
              'BackFaceLighting', 'reverselit', 'VertexNormals', -vn);
  hl = light ('Position', [1 0 .5]);
  lighting gouraud
  title ({'BackFaceLighting', '"reverselit"', 'isonormals(...,"negate")'});

 subplot (2, 3, 2);
  view (140, 20);
  axis equal
  hp = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
              'BackFaceLighting', 'lit', 'VertexNormals', -vn);
  hl = light ('Position', [1 0 .5]);
  lighting gouraud
  title ({'BackFaceLighting', '"lit"', 'isonormals(...,"negate")'});

 subplot (2, 3, 3);
  view (140, 20);
  axis equal
  hp = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
              'BackFaceLighting', 'unlit', 'VertexNormals', -vn);
  hl = light ('Position', [1 0 .5]);
  lighting gouraud
  title ({'BackFaceLighting', '"unlit"', 'isonormals(...,"negate")'});

 subplot (2, 3, 4);
  view (140, 20);
  axis equal
  hp = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
              'BackFaceLighting', 'reverselit', 'VertexNormals', vn);
  hl = light ('Position', [1 0 .5]);
  lighting gouraud
  title ({'BackFaceLighting', '"reverselit"', 'isonormals(...)'});

 subplot (2, 3, 5);
  view (140, 20);
  axis equal
  hp = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
              'BackFaceLighting', 'lit', 'VertexNormals', vn);
  hl = light ('Position', [1 0 .5]);
  lighting gouraud
  title ({'BackFaceLighting', '"lit"', 'isonormals(...)'});

 subplot (2, 3, 6);
  view (140, 20);
  axis equal
  hp = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', ...
              'BackFaceLighting', 'unlit', 'VertexNormals', vn);
  hl = light ('Position', [1 0 .5]);
  lighting gouraud
  title ({'BackFaceLighting', '"unlit"', 'isonormals(...)'});

end

try
  if (~ exist ('light_09.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_09 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_09.png" ... ');
      tic ();
      print ('-dpng', 'light_09.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_09.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_09: %s\n', lasterr ());
  err_fid = fopen ('light_09.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_10 ()
    
 %% Colored patch
 clf;
 [x,y,z] = meshgrid (-.2:0.02:.2, -.2:0.02:.2, -.2:0.02:.2);
 val = (x.^2 + y.^2 + z.^2);

 h_axes = axes ();
 view (3);
 fv = isosurface (x, y, z, val, .039, z);
 h_patch = patch (fv, 'FaceColor', 'flat', 'EdgeColor', 'none', ...
                      'FaceLighting', 'Gouraud');
 set (h_patch, 'SpecularExponent', 15);
 isonormals (x, y, z, val, h_patch);
 h_light = light ('Position', [-1 1 1]);
 view (3);
 axis tight
 axis equal
 title ('Colored patch');

end

try
  if (~ exist ('light_10.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_10 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_10.png" ... ');
      tic ();
      print ('-dpng', 'light_10.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_10.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_10: %s\n', lasterr ());
  err_fid = fopen ('light_10.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_11 ()
    
 %% Colored mesh (patch)
 clf;
 [x,y,z] = meshgrid (-.2:0.05:.2, -.2:0.05:.2, -.2:0.05:.2);
 val = (x.^2 + y.^2 + z.^2);

 h_axes = axes ();
 fv = isosurface (x, y, z, val, .039, z);
 h_patch = patch (fv, 'FaceColor', 'w', 'EdgeColor', 'interp');
 isonormals (x, y, z, val, h_patch);
 h_light = light ();
 lighting gouraud
 view (3);
 axis tight;
 axis equal;
 box off;
 title ('Colored mesh (patch)');

end

try
  if (~ exist ('light_11.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_11 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_11.png" ... ');
      tic ();
      print ('-dpng', 'light_11.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_11.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_11: %s\n', lasterr ());
  err_fid = fopen ('light_11.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_12 ()
    
 %% Colored mesh (surface)
 clf;
 h_mesh = mesh (peaks);
 title ('Colored mesh (surface)');
 h_light = light ();
 lighting gouraud

end

try
  if (~ exist ('light_12.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_12 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_12.png" ... ');
      tic ();
      print ('-dpng', 'light_12.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_12.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_12: %s\n', lasterr ());
  err_fid = fopen ('light_12.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_13 ()
    
 %% Light in hggroup
 clf;
 h_mesh = mesh (peaks);
 h_hg = hggroup ();
 title ('Light in hggroup');
 h_light = light ('Parent', h_hg);
 lighting gouraud

end

try
  if (~ exist ('light_13.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_13 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_13.png" ... ');
      tic ();
      print ('-dpng', 'light_13.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_13.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_13: %s\n', lasterr ());
  err_fid = fopen ('light_13.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function light_14 ()
    
 %% Style local/infinite
 clf;
 [x,y,z] = meshgrid (-.2:0.02:.2, -.2:0.02:.2, -.2:0.02:.2);
 val = (x.^2 + y.^2 + z.^2);

 h_axes1 = subplot (1,2,1);
  fv = isosurface (x, y, z, val, .039);
  h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none');
  isonormals (x, y, z, val, h_patch);
  title ('"Style" = "infinite" (default)');
  h_light = light ('Position', [.3 0 .3]);
  lighting gouraud
  view (3);
  axis equal

 h_axes2 = subplot (1,2,2);
  fv = isosurface (x, y, z, val, .039);
  h_patch = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none');
  isonormals (x, y, z, val, h_patch);
  title ('"Style" = "local"');
  h_light = light ('Style', 'local', 'Position', [.3 0 .3]);
  lighting gouraud
  view (3);
  axis equal

end

try
  if (~ exist ('light_14.png', 'file'))
    rand ('seed', 1);
    tic ();
    light_14 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "light_14.png" ... ');
      tic ();
      print ('-dpng', 'light_14.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "light_14.png" already exists.\n');
  end
catch
  fprintf ('ERROR in light_14: %s\n', lasterr ());
  err_fid = fopen ('light_14.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function line_01 ()
    
 clf;
 line ([0 1], [0.8 0.8], 'linestyle', '-', 'color', 'b');
 line ([0 1], [0.6 0.6], 'linestyle', '--', 'color', 'g');
 line ([0 1], [0.4 0.4], 'linestyle', ':', 'color', 'r');
 line ([0 1], [0.2 0.2], 'linestyle', '-.', 'color', 'k');
 ylim ([0 1]);
 title ('line() with various linestyles');
 legend ('"-"', '"--"', '":"', '"-."', 'location', 'eastoutside');

end

try
  if (~ exist ('line_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    line_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "line_01.png" ... ');
      tic ();
      print ('-dpng', 'line_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "line_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in line_01: %s\n', lasterr ());
  err_fid = fopen ('line_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function line_02 ()
    
 clf;
 x = 0:0.3:10;
 y1 = cos (x);
 y2 = sin (x);
 subplot (3,1,1);
  args = {'color', 'b', 'marker', 's'};
  line ([x(:), x(:)], [y1(:), y2(:)], args{:});
  title ('Test broadcasting for line()');
 subplot (3,1,2);
  line (x(:), [y1(:), y2(:)], args{:});
 subplot (3,1,3);
  line ([x(:), x(:)+pi/2], y1(:), args{:});
  xlim ([0 10]);

end

try
  if (~ exist ('line_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    line_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "line_02.png" ... ');
      tic ();
      print ('-dpng', 'line_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "line_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in line_02: %s\n', lasterr ());
  err_fid = fopen ('line_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function loglog_01 ()
    
 clf;
 t = 1:0.01:10;
 x = sort ((t .* (1 + rand (size (t)))) .^ 2);
 y = (t .* (1 + rand (size (t)))) .^ 2;
 loglog (x, y);
 title ({'loglog() plot', 'Both axes are logarithmic'});

end

try
  if (~ exist ('loglog_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    loglog_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "loglog_01.png" ... ');
      tic ();
      print ('-dpng', 'loglog_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "loglog_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in loglog_01: %s\n', lasterr ());
  err_fid = fopen ('loglog_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function loglog_02 ()
    
 clf;
 a = logspace (-5, 1, 10);
 b =-logspace (-5, 1, 10);

 subplot (1,2,1);
  loglog (a, b);
  title ('loglog (a, b)');

 subplot (1,2,2);
  loglog (a, abs (b));
  set (gca, 'ydir', 'reverse');
  title ('loglog (a, abs (b))');

end

try
  if (~ exist ('loglog_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    loglog_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "loglog_02.png" ... ');
      tic ();
      print ('-dpng', 'loglog_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "loglog_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in loglog_02: %s\n', lasterr ());
  err_fid = fopen ('loglog_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function loglogerr_01 ()
    
 clf;
 x = exp (log (0.01):0.2:log (10));
 y = wblpdf (x, 3, 2);
 eyu = 2*rand (size (y)) .* y;
 eyl = 0.5*rand (size (y)) .* y;
 loglogerr (x, y, eyl, eyu, '#~x-');
 xlim (x([1, end]));
 title ({'loglogerr(): loglog() plot with errorbars', ...
         'Both axes are logarithmic'});

end

try
  if (~ exist ('loglogerr_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    loglogerr_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "loglogerr_01.png" ... ');
      tic ();
      print ('-dpng', 'loglogerr_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "loglogerr_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in loglogerr_01: %s\n', lasterr ());
  err_fid = fopen ('loglogerr_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function mesh_01 ()
    
 clf;
 x = logspace (0,1,11);
 z = x'*x;
 mesh (x, x, z);
 xlabel 'X-axis';
 ylabel 'Y-axis';
 zlabel 'Z-axis';
 title ('mesh() with color proportional to height');

end

try
  if (~ exist ('mesh_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    mesh_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "mesh_01.png" ... ');
      tic ();
      print ('-dpng', 'mesh_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "mesh_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in mesh_01: %s\n', lasterr ());
  err_fid = fopen ('mesh_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function mesh_02 ()
    
 clf;
 x = logspace (0,1,11);
 z = x'*x;
 mesh (x, x, z, z.^2);
 xlabel 'X-axis';
 ylabel 'Y-axis';
 zlabel 'linear scale';
 title ('mesh() with color proportional to Z^2');

end

try
  if (~ exist ('mesh_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    mesh_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "mesh_02.png" ... ');
      tic ();
      print ('-dpng', 'mesh_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "mesh_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in mesh_02: %s\n', lasterr ());
  err_fid = fopen ('mesh_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function mesh_03 ()
    
 clf;
 x = logspace (0,1,11);
 z = x'*x;
 mesh (x, x, z, z.^2);
 set (gca, 'zscale', 'log');
 xlabel 'X-axis';
 ylabel 'Y-axis';
 zlabel 'log scale';
 title ({'mesh() with color proportional to Z^2', 'Z-axis is log scale'});
 try
   if (strcmp (get (gcf, '__graphics_toolkit__'), 'gnuplot'))
     title ({'Gnuplot: mesh color is wrong', 'This is a Gnuplot bug'});
   end
 catch
 end

end

try
  if (~ exist ('mesh_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    mesh_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "mesh_03.png" ... ');
      tic ();
      print ('-dpng', 'mesh_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "mesh_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in mesh_03: %s\n', lasterr ());
  err_fid = fopen ('mesh_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function mesh_04 ()
    
 clf;
 x = logspace (0,1,11);
 z = x'*x;
 mesh (x, x, z, 'facecolor', 'none', 'edgecolor', 'c');
 xlabel 'X-axis';
 ylabel 'Y-axis';
 zlabel 'Z-axis';
 title ({'mesh() default properties overridden', ...
         'transparent mesh with cyan color'});

end

try
  if (~ exist ('mesh_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    mesh_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "mesh_04.png" ... ');
      tic ();
      print ('-dpng', 'mesh_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "mesh_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in mesh_04: %s\n', lasterr ());
  err_fid = fopen ('mesh_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function meshc_01 ()
    
 clf;
 colormap ('default');
 [X, Y] = meshgrid (linspace (-3, 3, 40));
 Z = sqrt (abs (X .* Y)) ./ (1 + X.^2 + Y.^2);
 meshc (X, Y, Z);
 title ('meshc() combines mesh/contour plots');

end

try
  if (~ exist ('meshc_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    meshc_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "meshc_01.png" ... ');
      tic ();
      print ('-dpng', 'meshc_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "meshc_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in meshc_01: %s\n', lasterr ());
  err_fid = fopen ('meshc_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function meshz_01 ()
    
 clf;
 colormap ('default');
 Z = peaks ();
 meshz (Z);
 title ('meshz() plot of peaks() function');

end

try
  if (~ exist ('meshz_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    meshz_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "meshz_01.png" ... ');
      tic ();
      print ('-dpng', 'meshz_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "meshz_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in meshz_01: %s\n', lasterr ());
  err_fid = fopen ('meshz_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function meshz_02 ()
    
 clf;
 colormap ('default');
 Z = peaks ();
 subplot (1,2,1)
  mesh (Z);
  daspect ([2.5, 2.5, 1]);
  title ('mesh() plot');
 subplot (1,2,2)
  meshz (Z);
  daspect ([2.5, 2.5, 1]);
  title ('meshz() plot');

end

try
  if (~ exist ('meshz_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    meshz_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "meshz_02.png" ... ');
      tic ();
      print ('-dpng', 'meshz_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "meshz_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in meshz_02: %s\n', lasterr ());
  err_fid = fopen ('meshz_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function meshz_03 ()
    
 clf;
 colormap ('default');
 [X,Y,Z] = peaks ();
 [fx, fy] = gradient (Z);
 C = sqrt (fx.^2 + fy.^2);
 meshz (X,Y,Z,C);
 title ('meshz() plot with color determined by gradient');

end

try
  if (~ exist ('meshz_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    meshz_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "meshz_03.png" ... ');
      tic ();
      print ('-dpng', 'meshz_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "meshz_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in meshz_03: %s\n', lasterr ());
  err_fid = fopen ('meshz_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pareto_01 ()
    
 clf;
 colormap (jet (64));
 Cheese = {'Cheddar', 'Swiss', 'Camembert', 'Munster', 'Stilton', 'Blue'};
 Sold = [105, 30, 70, 10, 15, 20];
 pareto (Sold, Cheese);
 title ('pareto() demo #1');

end

try
  if (~ exist ('pareto_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    pareto_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pareto_01.png" ... ');
      tic ();
      print ('-dpng', 'pareto_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pareto_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pareto_01: %s\n', lasterr ());
  err_fid = fopen ('pareto_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pareto_02 ()
    
 clf;
 %% Suppose that we want establish which products makes 80% of turnover.
 Codes = {'AB4','BD7','CF8','CC5','AD11','BB5','BB3','AD8','DF3','DE7'};
 Value = [2.35 7.9 2.45 1.1 0.15 13.45 5.4 2.05 0.85 1.65]';
 SoldUnits = [54723 41114 16939 1576091 168000 687197 120222 168195, ...
              1084118 55576]';
 pareto (Value.*SoldUnits, Codes);
 title ('pareto() demo #2');

end

try
  if (~ exist ('pareto_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    pareto_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pareto_02.png" ... ');
      tic ();
      print ('-dpng', 'pareto_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pareto_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pareto_02: %s\n', lasterr ());
  err_fid = fopen ('pareto_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function patch_01 ()
    
 clf;
 t1 = (1/16:1/8:1)' * 2*pi;
 t2 = ((1/16:1/8:1)' + 1/32) * 2*pi;
 x1 = sin (t1) - 0.8;
 y1 = cos (t1);
 x2 = sin (t2) + 0.8;
 y2 = cos (t2);
 patch ([x1,x2], [y1,y2], 'r');
 title ('patches with same number of vertices');

end

try
  if (~ exist ('patch_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    patch_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "patch_01.png" ... ');
      tic ();
      print ('-dpng', 'patch_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "patch_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in patch_01: %s\n', lasterr ());
  err_fid = fopen ('patch_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function patch_02 ()
    
 clf;
 t1 = (1/16:1/8:1)' * 2*pi;
 t2 = ((1/16:1/16:1)' + 1/32) * 2*pi;
 x1 = sin (t1) - 0.8;
 y1 = cos (t1);
 x2 = sin (t2) + 0.8;
 y2 = cos (t2);
 patch ([[x1;NaN(8,1)],x2], [[y1;NaN(8,1)],y2], 'r');
 title ('Unclosed patch by using NaN');

end

try
  if (~ exist ('patch_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    patch_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "patch_02.png" ... ');
      tic ();
      print ('-dpng', 'patch_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "patch_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in patch_02: %s\n', lasterr ());
  err_fid = fopen ('patch_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function patch_03 ()
    
 clf;
 t1 = (1/16:1/8:1)' * 2*pi;
 t2 = ((1/16:1/16:1)' + 1/32) * 2*pi;
 x1 = sin (t1) - 0.8;
 y1 = cos (t1);
 x2 = sin (t2) + 0.8;
 y2 = cos (t2);
 vert = [x1, y1; x2, y2];
 fac = [1:8,NaN(1,8);9:24];
 patch ('Faces',fac, 'Vertices',vert, 'FaceColor','r');
 title ('patch() with separate specification of Faces and Vertices');

end

try
  if (~ exist ('patch_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    patch_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "patch_03.png" ... ');
      tic ();
      print ('-dpng', 'patch_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "patch_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in patch_03: %s\n', lasterr ());
  err_fid = fopen ('patch_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function patch_04 ()
    
 clf;
 t1 = (1/16:1/8:1)' * 2*pi;
 t2 = ((1/16:1/16:1)' + 1/32) * 2*pi;
 x1 = sin (t1) - 0.8;
 y1 = cos (t1);
 x2 = sin (t2) + 0.8;
 y2 = cos (t2);
 vert = [x1, y1; x2, y2];
 p.Faces = [1:8,NaN(1,8);9:24];
 p.FaceColor = 'flat';
 patch (p, 'Vertices', vert, 'FaceVertexCData', [0, 1, 0; 0, 0, 1]);
 title ('patch() with specification of color for each vertex');

end

try
  if (~ exist ('patch_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    patch_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "patch_04.png" ... ');
      tic ();
      print ('-dpng', 'patch_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "patch_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in patch_04: %s\n', lasterr ());
  err_fid = fopen ('patch_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function patch_05 ()
    
 %% Property change on multiple patches
 clf;
 t1 = (1/16:1/8:1)' * 2*pi;
 t2 = ((1/16:1/8:1)' + 1/32) * 2*pi;
 x1 = sin (t1) - 0.8;
 y1 = cos (t1);
 x2 = sin (t2) + 0.8;
 y2 = cos (t2);
 h = patch ([x1,x2], [y1,y2], cat (3, [0,0],[1,0],[0,1]));
 pause (1);
 set (h, 'FaceColor', 'r');
 title ('change color on multiple patch() objects');

end

try
  if (~ exist ('patch_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    patch_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "patch_05.png" ... ');
      tic ();
      print ('-dpng', 'patch_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "patch_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in patch_05: %s\n', lasterr ());
  err_fid = fopen ('patch_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function patch_06 ()
    
 clf;
 vertices = [0, 0, 0;
             1, 0, 0;
             1, 1, 0;
             0, 1, 0;
             0.5, 0.5, 1];
 faces = [1, 2, 5;
          2, 3, 5;
          3, 4, 5;
          4, 1, 5];
 patch ('Vertices', vertices, 'Faces', faces, ...
        'FaceVertexCData', jet (4), 'FaceColor', 'flat');
 view (-37.5, 30);
 box off;
 title ('"FaceColor" = "flat"');

end

try
  if (~ exist ('patch_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    patch_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "patch_06.png" ... ');
      tic ();
      print ('-dpng', 'patch_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "patch_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in patch_06: %s\n', lasterr ());
  err_fid = fopen ('patch_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function patch_07 ()
    
 clf;
 vertices = [0, 0, 0;
             1, 0, 0;
             1, 1, 0;
             0, 1, 0;
             0.5, 0.5, 1];
 faces = [1, 2, 5;
          2, 3, 5;
          3, 4, 5;
          4, 1, 5];
 patch  ('Vertices', vertices, 'Faces', faces, ...
        'FaceVertexCData', jet (5), 'FaceColor', 'interp');
 view (-37.5, 30);
 box off;
 title ('"FaceColor" = "interp"');

end

try
  if (~ exist ('patch_07.png', 'file'))
    rand ('seed', 1);
    tic ();
    patch_07 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "patch_07.png" ... ');
      tic ();
      print ('-dpng', 'patch_07.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "patch_07.png" already exists.\n');
  end
catch
  fprintf ('ERROR in patch_07: %s\n', lasterr ());
  err_fid = fopen ('patch_07.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function patch_08 ()
    
 clf;
 colormap (jet (64));
 x = [0 1 1 0];
 y = [0 0 1 1];
 subplot (2,1,1);
  title ('Blue, Light Green, and Red Horizontal Bars');
  patch (x, y + 0, 1);
  patch (x, y + 1, 2);
  patch (x, y + 2, 3);
 subplot (2,1,2);
  title ('Blue, Light Green, and Red Vertical Bars');
  patch (x + 0, y, 1 * ones (size (x)));
  patch (x + 1, y, 2 * ones (size (x)));
  patch (x + 2, y, 3 * ones (size (x)));

end

try
  if (~ exist ('patch_08.png', 'file'))
    rand ('seed', 1);
    tic ();
    patch_08 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "patch_08.png" ... ');
      tic ();
      print ('-dpng', 'patch_08.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "patch_08.png" already exists.\n');
  end
catch
  fprintf ('ERROR in patch_08: %s\n', lasterr ());
  err_fid = fopen ('patch_08.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function patch_09 ()
    
 clf;
 colormap (jet (64));
 x = [0 1 1 0];
 y = [0 0 1 1];
 subplot (2,1,1);
  title ('Blue horizontal bars: Dark to Light');
  patch (x, y + 0, 1, 'cdatamapping', 'direct');
  patch (x, y + 1, 9, 'cdatamapping', 'direct');
  patch (x, y + 2, 17, 'cdatamapping', 'direct');
 subplot (2,1,2);
  title ('Blue vertical bars: Dark to Light');
  patch (x + 0, y, 1 * ones (size (x)), 'cdatamapping', 'direct');
  patch (x + 1, y, 9 * ones (size (x)), 'cdatamapping', 'direct');
  patch (x + 2, y, 17 * ones (size (x)), 'cdatamapping', 'direct');

end

try
  if (~ exist ('patch_09.png', 'file'))
    rand ('seed', 1);
    tic ();
    patch_09 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "patch_09.png" ... ');
      tic ();
      print ('-dpng', 'patch_09.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "patch_09.png" already exists.\n');
  end
catch
  fprintf ('ERROR in patch_09: %s\n', lasterr ());
  err_fid = fopen ('patch_09.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function patch_10 ()
    
 clf;
 colormap (jet (64));
 x = [ 0 0; 1 1; 1 0 ];
 y = [ 0 0; 0 1; 1 1 ];
 p = patch (x, y, 'b');
 set (p, 'cdatamapping', 'direct', 'facecolor', 'flat', 'cdata', [1 32]);
 title ('Direct mapping of colors: Light-Green UL and Blue LR triangles');

end

try
  if (~ exist ('patch_10.png', 'file'))
    rand ('seed', 1);
    tic ();
    patch_10 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "patch_10.png" ... ');
      tic ();
      print ('-dpng', 'patch_10.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "patch_10.png" already exists.\n');
  end
catch
  fprintf ('ERROR in patch_10: %s\n', lasterr ());
  err_fid = fopen ('patch_10.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function patch_11 ()
    
 clf;
 colormap (jet (64));
 x = [ 0 0; 1 1; 1 0 ];
 y = [ 0 0; 0 1; 1 1 ];
 p = patch (x, y, [1 32]);
 title ('Autoscaling of colors: Red UL and Blue LR triangles');

end

try
  if (~ exist ('patch_11.png', 'file'))
    rand ('seed', 1);
    tic ();
    patch_11 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "patch_11.png" ... ');
      tic ();
      print ('-dpng', 'patch_11.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "patch_11.png" already exists.\n');
  end
catch
  fprintf ('ERROR in patch_11: %s\n', lasterr ());
  err_fid = fopen ('patch_11.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pcolor_01 ()
    
 clf;
 colormap ('default');
 Z = peaks ();
 pcolor (Z);
 title ('pcolor() of peaks with facet shading');

end

try
  if (~ exist ('pcolor_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    pcolor_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pcolor_01.png" ... ');
      tic ();
      print ('-dpng', 'pcolor_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pcolor_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pcolor_01: %s\n', lasterr ());
  err_fid = fopen ('pcolor_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pcolor_02 ()
    
 clf;
 colormap ('default');
 [X,Y,Z] = sombrero ();
 [Fx,Fy] = gradient (Z);
 pcolor (X,Y,Fx+Fy);
 shading interp;
 axis tight;
 title ('pcolor() of peaks with interp shading');

end

try
  if (~ exist ('pcolor_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    pcolor_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pcolor_02.png" ... ');
      tic ();
      print ('-dpng', 'pcolor_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pcolor_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pcolor_02: %s\n', lasterr ());
  err_fid = fopen ('pcolor_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pie_01 ()
    
 clf;
 pie ([3, 2, 1], [0, 0, 1]);
 colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 title ('pie() with exploded wedge');

end

try
  if (~ exist ('pie_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    pie_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pie_01.png" ... ');
      tic ();
      print ('-dpng', 'pie_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pie_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pie_01: %s\n', lasterr ());
  err_fid = fopen ('pie_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pie_02 ()
    
 clf;
 pie ([3, 2, 1], [0, 0, 1], {'Cheddar', 'Swiss', 'Camembert'});
 colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 axis ([-2,2,-2,2]);
 title ('pie() with labels');

end

try
  if (~ exist ('pie_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    pie_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pie_02.png" ... ');
      tic ();
      print ('-dpng', 'pie_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pie_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pie_02: %s\n', lasterr ());
  err_fid = fopen ('pie_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pie_03 ()
    
 clf;
 pie ([0.17, 0.34, 0.41], {'Cheddar', 'Swiss', 'Camembert'});
 colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 axis ([-2,2,-2,2]);
 title ('pie() with missing slice');

end

try
  if (~ exist ('pie_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    pie_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pie_03.png" ... ');
      tic ();
      print ('-dpng', 'pie_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pie_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pie_03: %s\n', lasterr ());
  err_fid = fopen ('pie_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pie3_01 ()
    
 clf;
 pie3 ([5:-1:1], [0, 0, 1, 0, 0]);
 colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 title ('pie3() with exploded wedge');

end

try
  if (~ exist ('pie3_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    pie3_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pie3_01.png" ... ');
      tic ();
      print ('-dpng', 'pie3_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pie3_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pie3_01: %s\n', lasterr ());
  err_fid = fopen ('pie3_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pie3_02 ()
    
 clf;
 pie3 ([3, 2, 1], [0, 0, 1], {'Cheddar', 'Swiss', 'Camembert'});
 colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 axis ([-2,2,-2,2]);
 title ('pie3() with labels');

end

try
  if (~ exist ('pie3_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    pie3_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pie3_02.png" ... ');
      tic ();
      print ('-dpng', 'pie3_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pie3_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pie3_02: %s\n', lasterr ());
  err_fid = fopen ('pie3_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pie3_03 ()
    
 clf;
 pie3 ([0.17, 0.34, 0.41], {'Cheddar', 'Swiss', 'Camembert'});
 colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 axis ([-2,2,-2,2]);
 title ('pie3() with missing slice');

end

try
  if (~ exist ('pie3_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    pie3_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pie3_03.png" ... ');
      tic ();
      print ('-dpng', 'pie3_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pie3_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pie3_03: %s\n', lasterr ());
  err_fid = fopen ('pie3_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plot_01 ()
    
 clf;
 x = 1:5;  y = 1:5;
 plot (x,y,'g');
 title ('plot() of green line at 45 degrees');

end

try
  if (~ exist ('plot_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    plot_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plot_01.png" ... ');
      tic ();
      print ('-dpng', 'plot_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plot_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plot_01: %s\n', lasterr ());
  err_fid = fopen ('plot_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plot_02 ()
    
 clf;
 x = 1:5;  y = 1:5;
 plot (x,y,'g*');
 title ('plot() of green stars along a line at 45 degrees');

end

try
  if (~ exist ('plot_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    plot_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plot_02.png" ... ');
      tic ();
      print ('-dpng', 'plot_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plot_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plot_02: %s\n', lasterr ());
  err_fid = fopen ('plot_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plot_03 ()
    
 clf;
 x1 = 1:5;  y1 = 1:5;
 x2 = 5:9; y2 = 5:-1:1;
 plot (x1,y1,'bo-', x2,y2,'rs-');
 axis ('tight');
 title ({'plot() of blue circles ascending and red squares descending';
         'connecting lines drawn'});

end

try
  if (~ exist ('plot_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    plot_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plot_03.png" ... ');
      tic ();
      print ('-dpng', 'plot_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plot_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plot_03: %s\n', lasterr ());
  err_fid = fopen ('plot_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plot_04 ()
    
 clf;
 x = 0:10;
 plot (x, rand (numel (x), 3));
 axis ([0 10 0 1]);
 title ({'Three random variables', 'x[1x11], y[11x3]'});

end

try
  if (~ exist ('plot_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    plot_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plot_04.png" ... ');
      tic ();
      print ('-dpng', 'plot_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plot_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plot_04: %s\n', lasterr ());
  err_fid = fopen ('plot_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plot_05 ()
    
 clf;
 x = 0:10;
 plot (x, rand (3, numel (x)));
 axis ([0 10 0 1]);
 title ({'Three random variables', 'x[1x11], y[3x11]'});

end

try
  if (~ exist ('plot_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    plot_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plot_05.png" ... ');
      tic ();
      print ('-dpng', 'plot_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plot_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plot_05: %s\n', lasterr ());
  err_fid = fopen ('plot_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plot_06 ()
    
 clf;
 x = 0:10;
 plot (repmat (x, 2, 1), rand (2, numel (x)), '-s');
 axis ([0 10 0 1]);
 title ({'Vertical lines with random height and lengths', ...
         'x[2x11], y[2,11]'});

end

try
  if (~ exist ('plot_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    plot_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plot_06.png" ... ');
      tic ();
      print ('-dpng', 'plot_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plot_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plot_06: %s\n', lasterr ());
  err_fid = fopen ('plot_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plot_07 ()
    
 clf;
 x = 0:10;
 plot (repmat (x(:), 1, 2), rand (numel (x), 2));
 axis ([0 10 0 1]);
 title ({'Two random variables', 'x[11x2], y[11x2]'});

end

try
  if (~ exist ('plot_07.png', 'file'))
    rand ('seed', 1);
    tic ();
    plot_07 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plot_07.png" ... ');
      tic ();
      print ('-dpng', 'plot_07.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plot_07.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plot_07: %s\n', lasterr ());
  err_fid = fopen ('plot_07.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plot_08 ()
    
 clf;
 x = 0:10;
 shape = [1, 1, numel(x), 2];
 x = reshape (repmat (x(:), 1, 2), shape);
 y = rand (shape);
 plot (x, y);
 axis ([0 10 0 1]);
 title ({'Two random variables', 'squeezed from 4-D arrays'});

end

try
  if (~ exist ('plot_08.png', 'file'))
    rand ('seed', 1);
    tic ();
    plot_08 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plot_08.png" ... ');
      tic ();
      print ('-dpng', 'plot_08.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plot_08.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plot_08: %s\n', lasterr ());
  err_fid = fopen ('plot_08.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plot3_01 ()
    
 clf;
 z = [0:0.05:5];
 plot3 (cos (2*pi*z), sin (2*pi*z), z);
 legend ('helix');
 title ('plot3() of a helix');

end

try
  if (~ exist ('plot3_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    plot3_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plot3_01.png" ... ');
      tic ();
      print ('-dpng', 'plot3_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plot3_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plot3_01: %s\n', lasterr ());
  err_fid = fopen ('plot3_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plot3_02 ()
    
 clf;
 z = [0:0.05:5];
 plot3 (z, exp (2i*pi*z));
 legend ('complex sinusoid');
 title ('plot3() with complex input');

end

try
  if (~ exist ('plot3_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    plot3_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plot3_02.png" ... ');
      tic ();
      print ('-dpng', 'plot3_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plot3_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plot3_02: %s\n', lasterr ());
  err_fid = fopen ('plot3_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plotmatrix_01 ()
    
 clf;
 plotmatrix (randn (100, 3), 'g+');
 title ('plotmatrix() demo #1');

end

try
  if (~ exist ('plotmatrix_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    plotmatrix_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plotmatrix_01.png" ... ');
      tic ();
      print ('-dpng', 'plotmatrix_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plotmatrix_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plotmatrix_01: %s\n', lasterr ());
  err_fid = fopen ('plotmatrix_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plotyy_01 ()
    
 clf;
 x = 0:0.1:2*pi;
 y1 = sin (x);
 y2 = exp (x - 1);
 ax = plotyy (x,y1, x-1,y2, @plot, @semilogy);
 xlabel ('X');
 ylabel (ax(1), 'Axis 1');
 ylabel (ax(2), 'Axis 2');
 lcolor = get (gca, 'ColorOrder')(1,:);
 rcolor = get (gca, 'ColorOrder')(2,:);
 text (0.5, 0.5, 'Left Axis', ...
       'color', lcolor, 'horizontalalignment', 'center', 'parent', ax(1));
 text (4.5, 80, 'Right Axis', ...
       'color', rcolor, 'horizontalalignment', 'center', 'parent', ax(2));
 title ({'plotyy() example'; 'left axis uses @plot, right axis uses @semilogy'});

end

try
  if (~ exist ('plotyy_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    plotyy_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plotyy_01.png" ... ');
      tic ();
      print ('-dpng', 'plotyy_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plotyy_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plotyy_01: %s\n', lasterr ());
  err_fid = fopen ('plotyy_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function plotyy_02 ()
    
 clf;
 colormap ('default');
 x = linspace (-1, 1, 201);
 subplot (2,2,1);
  plotyy (x,sin(pi*x), x,10*cos(pi*x));
  title ('plotyy() in subplot');
 subplot (2,2,2);
  surf (peaks (25));
 subplot (2,2,3);
  contour (peaks (25));
 subplot (2,2,4);
  plotyy (x,10*sin(2*pi*x), x,cos(2*pi*x));
  title ('plotyy() in subplot');
  axis square;

end

try
  if (~ exist ('plotyy_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    plotyy_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "plotyy_02.png" ... ');
      tic ();
      print ('-dpng', 'plotyy_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "plotyy_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in plotyy_02: %s\n', lasterr ());
  err_fid = fopen ('plotyy_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function polar_01 ()
    
 clf;
 theta = linspace (0,2*pi,1000);
 rho = sin (7*theta);
 polar (theta, rho);
 title ('polar() plot');

end

try
  if (~ exist ('polar_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    polar_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "polar_01.png" ... ');
      tic ();
      print ('-dpng', 'polar_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "polar_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in polar_01: %s\n', lasterr ());
  err_fid = fopen ('polar_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function polar_02 ()
    
 clf;
 theta = linspace (0,2*pi,1000);
 cplx = theta + i*sin (7*theta);
 polar (cplx, 'g');
 title ('polar() plot of complex data');

end

try
  if (~ exist ('polar_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    polar_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "polar_02.png" ... ');
      tic ();
      print ('-dpng', 'polar_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "polar_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in polar_02: %s\n', lasterr ());
  err_fid = fopen ('polar_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function polar_03 ()
    
 clf;
 theta = linspace (0,2*pi,1000);
 rho = sin (2*theta).*cos (2*theta);
 polar (theta, rho, '--r');
 set (gca, 'rtick', 0.1:0.1:0.6, 'ttick', 0:20:340);
 title ('polar() plot with finer grid');

end

try
  if (~ exist ('polar_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    polar_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "polar_03.png" ... ');
      tic ();
      print ('-dpng', 'polar_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "polar_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in polar_03: %s\n', lasterr ());
  err_fid = fopen ('polar_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function polar_04 ()
    
 clf;
 theta = linspace (0,2*pi,1000);
 rho = sin (2*theta).*cos (2*theta);
 polar (theta, rho, '--b');
 set (gca, 'fontsize', 12, 'linewidth', 2, 'color', [0.8 0.8 0.8]);
 title ('polar() plot with modified axis appearance');

end

try
  if (~ exist ('polar_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    polar_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "polar_04.png" ... ');
      tic ();
      print ('-dpng', 'polar_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "polar_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in polar_04: %s\n', lasterr ());
  err_fid = fopen ('polar_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function polar_05 ()
    
 clf;
 theta = linspace (0,8*pi,1000);
 rho = sin (5/4*theta);
 polar (theta, rho);
 set (gca, 'rtick', 0.2:0.2:1);
 title ('polar() plot');

end

try
  if (~ exist ('polar_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    polar_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "polar_05.png" ... ');
      tic ();
      print ('-dpng', 'polar_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "polar_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in polar_05: %s\n', lasterr ());
  err_fid = fopen ('polar_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function quiver_01 ()
    
 clf;
 [x,y] = meshgrid (1:2:20);
 h = quiver (x,y, sin (2*pi*x/10), sin (2*pi*y/10));
 title ('quiver() plot w/arrowheads (default)');

end

try
  if (~ exist ('quiver_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    quiver_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "quiver_01.png" ... ');
      tic ();
      print ('-dpng', 'quiver_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "quiver_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in quiver_01: %s\n', lasterr ());
  err_fid = fopen ('quiver_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function quiver_02 ()
    
 clf;
 [x,y] = meshgrid (1:2:20);
 h = quiver (x,y, sin (2*pi*x/10), sin (2*pi*y/10), 'o');
 title ('quiver() plot w/origin markers');

end

try
  if (~ exist ('quiver_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    quiver_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "quiver_02.png" ... ');
      tic ();
      print ('-dpng', 'quiver_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "quiver_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in quiver_02: %s\n', lasterr ());
  err_fid = fopen ('quiver_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function quiver_03 ()
    
 clf;
 [x,y] = meshgrid (1:2:20);
 h = quiver (x,y, sin (2*pi*x/10), sin (2*pi*y/10));
 set (h, 'marker', 'o');
 title ('quiver() plot w/origin markers and arrowheads');

end

try
  if (~ exist ('quiver_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    quiver_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "quiver_03.png" ... ');
      tic ();
      print ('-dpng', 'quiver_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "quiver_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in quiver_03: %s\n', lasterr ());
  err_fid = fopen ('quiver_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function quiver_04 ()
    
 clf;
 x = linspace (0, 3, 80);
 y = sin (2*pi*x);
 theta = 2*pi*x + pi/2;
 quiver (x, y, sin (theta)/10, cos (theta)/10, 0.4);
 axis equal tight;
 hold on; plot (x,y,'r'); hold off;
 title ('quiver() with scaled arrows');

end

try
  if (~ exist ('quiver_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    quiver_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "quiver_04.png" ... ');
      tic ();
      print ('-dpng', 'quiver_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "quiver_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in quiver_04: %s\n', lasterr ());
  err_fid = fopen ('quiver_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function quiver3_01 ()
    
 clf;
 colormap ('default');
 [x, y, z] = peaks (25);
 surf (x, y, z);
 hold on;
 [u, v, w] = surfnorm (x, y, z / 10);
 h = quiver3 (x, y, z, u, v, w);
 set (h, 'maxheadsize', 0.25);
 hold off;
 title ('quiver3() of surface normals to peaks() function');

end

try
  if (~ exist ('quiver3_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    quiver3_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "quiver3_01.png" ... ');
      tic ();
      print ('-dpng', 'quiver3_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "quiver3_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in quiver3_01: %s\n', lasterr ());
  err_fid = fopen ('quiver3_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function quiver3_02 ()
    
 clf;
 colormap ('default');
 [x, y, z] = peaks (25);
 surf (x, y, z);
 hold on;
 [u, v, w] = surfnorm (x, y, z / 10);
 h = quiver3 (x, y, z, u, v, w);
 set (h, 'maxheadsize', 0.25);
 hold off;
 shading interp;
 title ({'quiver3() of surface normals to peaks() function'; ...
         'shading "interp"'});

end

try
  if (~ exist ('quiver3_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    quiver3_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "quiver3_02.png" ... ');
      tic ();
      print ('-dpng', 'quiver3_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "quiver3_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in quiver3_02: %s\n', lasterr ());
  err_fid = fopen ('quiver3_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function rectangle_01 ()
    
 clf;
 axis equal;
 rectangle ('Position', [0.05, 0.05, 0.9, 0.9], 'Curvature', [0.5, 0.5]);
 title ('rectangle() with corners curved');

end

try
  if (~ exist ('rectangle_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    rectangle_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "rectangle_01.png" ... ');
      tic ();
      print ('-dpng', 'rectangle_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "rectangle_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in rectangle_01: %s\n', lasterr ());
  err_fid = fopen ('rectangle_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function rectangle_02 ()
    
 clf;
 axis equal;
 rectangle ('Position', [0.05, 0.05, 0.9, 0.4], 'Curvature', 1.0);
 title ('rectangle() with sides as complete arcs');

end

try
  if (~ exist ('rectangle_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    rectangle_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "rectangle_02.png" ... ');
      tic ();
      print ('-dpng', 'rectangle_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "rectangle_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in rectangle_02: %s\n', lasterr ());
  err_fid = fopen ('rectangle_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function rectangle_03 ()
    
 clf;
 axis equal;
 h = rectangle ('Position', [0.05, 0.05, 0.9, 0.4], 'Curvature', 1.0);
 set (h, 'FaceColor', [0, 1, 0]);
 title ('rectangle() with FaceColor = green');

end

try
  if (~ exist ('rectangle_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    rectangle_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "rectangle_03.png" ... ');
      tic ();
      print ('-dpng', 'rectangle_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "rectangle_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in rectangle_03: %s\n', lasterr ());
  err_fid = fopen ('rectangle_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function reducepatch_01 ()
    
 clf;
 [x,y,z] = meshgrid (-2:0.5:2, -2:0.5:2, -2:0.5:2);
 val = x.^2 + y.^2 + z.^2;
 fv = isosurface (x, y, z, val, 1);
 ax1 = subplot (1, 2, 1);
 patch (fv, 'FaceColor', 'g');
 view (3);  axis equal;
 title ('Sphere with all faces');
 ax2 = subplot(1, 2, 2);
 patch (reducepatch (fv, 72), 'FaceColor', 'g');
 view (3);  axis equal;
 title ('Sphere with reduced number of faces');
 linkprop ([ax1, ax2], {'CameraPosition', 'CameraUpVector'});

end

try
  if (~ exist ('reducepatch_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    reducepatch_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "reducepatch_01.png" ... ');
      tic ();
      print ('-dpng', 'reducepatch_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "reducepatch_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in reducepatch_01: %s\n', lasterr ());
  err_fid = fopen ('reducepatch_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ribbon_01 ()
    
 clf;
 colormap ('default');
 [x, y, z] = sombrero ();
 ribbon (y, z);
 title ('ribbon() plot of sombrero()');

end

try
  if (~ exist ('ribbon_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ribbon_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ribbon_01.png" ... ');
      tic ();
      print ('-dpng', 'ribbon_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ribbon_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ribbon_01: %s\n', lasterr ());
  err_fid = fopen ('ribbon_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function rose_01 ()
    
 clf;
 rose (2*randn (1e5, 1), 8);
 title ('rose() angular histogram plot with 8 bins');

end

try
  if (~ exist ('rose_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    rose_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "rose_01.png" ... ');
      tic ();
      print ('-dpng', 'rose_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "rose_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in rose_01: %s\n', lasterr ());
  err_fid = fopen ('rose_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function rose_02 ()
    
 clf;
 rose ([2*randn(1e5, 1), pi + 2*randn(1e5, 1)]);
 title ('rose() angular histogram plot with 2 data series');

end

try
  if (~ exist ('rose_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    rose_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "rose_02.png" ... ');
      tic ();
      print ('-dpng', 'rose_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "rose_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in rose_02: %s\n', lasterr ());
  err_fid = fopen ('rose_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function rose_03 ()
    
 clf;
 rose ([0, 2, 3, 5], [0, pi/2, pi, 3*pi/2]);
 title ('rose() angular histogram plot with specified bins');

end

try
  if (~ exist ('rose_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    rose_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "rose_03.png" ... ');
      tic ();
      print ('-dpng', 'rose_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "rose_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in rose_03: %s\n', lasterr ());
  err_fid = fopen ('rose_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter_01 ()
    
 clf;
 x = randn (100, 1);
 y = randn (100, 1);
 scatter (x, y, 'r');
 title ('scatter() plot with red bubbles');

end

try
  if (~ exist ('scatter_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter_01.png" ... ');
      tic ();
      print ('-dpng', 'scatter_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter_01: %s\n', lasterr ());
  err_fid = fopen ('scatter_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter_02 ()
    
 clf;
 x = randn (100, 1);
 y = randn (100, 1);
 c = x .* y;
 scatter (x, y, 50, c, 'filled');
 title ('scatter() with colored filled bubbles');

end

try
  if (~ exist ('scatter_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter_02.png" ... ');
      tic ();
      print ('-dpng', 'scatter_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter_02: %s\n', lasterr ());
  err_fid = fopen ('scatter_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter_03 ()
    
 clf;
 x = randn (100, 1);
 y = randn (100, 1);
 scatter (x, y, [], sqrt (x.^2 + y.^2));
 title ({'scatter() plot'; ...
         'bubble color determined by distance from origin'});

end

try
  if (~ exist ('scatter_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter_03.png" ... ');
      tic ();
      print ('-dpng', 'scatter_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter_03: %s\n', lasterr ());
  err_fid = fopen ('scatter_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter_04 ()
    
 clf;
 rand_10x1_data5 = [0.777753, 0.093848, 0.183162, 0.399499, 0.337997, 0.686724, 0.073906, 0.651808, 0.869273, 0.137949];
 rand_10x1_data6 = [0.37460, 0.25027, 0.19510, 0.51182, 0.54704, 0.56087, 0.24853, 0.75443, 0.42712, 0.44273];
 x = rand_10x1_data5;
 y = rand_10x1_data6;
 h = scatter (x, y, [], 'r', 's');
 title ({'scatter() plot'; ...
         'color is red, marker is square'});

end

try
  if (~ exist ('scatter_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter_04.png" ... ');
      tic ();
      print ('-dpng', 'scatter_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter_04: %s\n', lasterr ());
  err_fid = fopen ('scatter_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter_05 ()
    
 clf;
 rand_10x1_data3 = [0.42262, 0.51623, 0.65992, 0.14999, 0.68385, 0.55929, 0.52251, 0.92204, 0.19762, 0.93726];
 rand_10x1_data4 = [0.020207, 0.527193, 0.443472, 0.061683, 0.370277, 0.947349, 0.249591, 0.666304, 0.134247, 0.920356];
 x = rand_10x1_data3;
 y = rand_10x1_data4;
 h = scatter (x, y, [], 'r', 's', 'filled');
 title ({'scatter() plot'; ...
         'color is red, marker is square, marker is filled'});

end

try
  if (~ exist ('scatter_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter_05.png" ... ');
      tic ();
      print ('-dpng', 'scatter_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter_05: %s\n', lasterr ());
  err_fid = fopen ('scatter_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter_06 ()
    
 clf;
 rand_10x1_data1 = [0.171577, 0.404796, 0.025469, 0.335309, 0.047814, 0.898480, 0.639599, 0.700247, 0.497798, 0.737940];
 rand_10x1_data2 = [0.75495, 0.83991, 0.80850, 0.73603, 0.19360, 0.72573, 0.69371, 0.74388, 0.13837, 0.54143];
 x = rand_10x1_data1;
 y = rand_10x1_data2;
 s = 36 - 30*log (x.^2 + y.^2);
 h = scatter (x, y, s, s, 's', 'filled');
 title ({'scatter() plot with filled square markers', ...
         'size and color of markers determined by algorithm'});

end

try
  if (~ exist ('scatter_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter_06.png" ... ');
      tic ();
      print ('-dpng', 'scatter_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter_06: %s\n', lasterr ());
  err_fid = fopen ('scatter_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter_07 ()
    
 clf;
 k = 1;
 for m = [1, 3]
   for n = [101, 50, 1]
     x = rand (n, 1);
     y = rand (n, 1);
     if (m > 1)
       str = 'Three Colors';
       idx = ceil (rand (n, 1) * 3);
       colors = eye (3);
       colors = colors(idx, :);
     else
       str = 'Random Colors';
       colors = rand (n, m);
     end
     if (n == 1)
       str = sprintf ('%s: 1 point', str);
     elseif (n < 100)
       str = sprintf ('%s: < 100 points', str);
     else
       str = sprintf ('%s: > 100 points', str);
     end
     subplot (2,3,k);
     k = k + 1;
     scatter (x, y, [], colors, 'filled');
     axis ([0 1 0 1]);
     title (str);
   end
 end

end

try
  if (~ exist ('scatter_07.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter_07 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter_07.png" ... ');
      tic ();
      print ('-dpng', 'scatter_07.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter_07.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter_07: %s\n', lasterr ());
  err_fid = fopen ('scatter_07.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter_08 ()
    
 clf;
 k = 1;
 for m = [1, 3]
   for n = [101, 50, 1]
     x = rand (n, 1);
     y = rand (n, 1);
     if (m > 1)
       str = 'Three Colors';
       idx = ceil (rand (n, 1) * 3);
       colors = eye (3);
       colors = colors(idx, :);
     else
       str = 'Random Colors';
       colors = rand (n, m);
     end
     if (n == 1)
       str = sprintf ('%s: 1 point', str);
     elseif (n < 100)
       str = sprintf ('%s: < 100 points', str);
     else
       str = sprintf ('%s: > 100 points', str);
     end
     subplot (2,3,k);
     k = k + 1;
     scatter (x, y, [], colors);
     axis ([0 1 0 1]);
     title (str);
   end
 end

end

try
  if (~ exist ('scatter_08.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter_08 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter_08.png" ... ');
      tic ();
      print ('-dpng', 'scatter_08.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter_08.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter_08: %s\n', lasterr ());
  err_fid = fopen ('scatter_08.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter3_01 ()
    
 clf;
 [x, y, z] = peaks (20);
 scatter3 (x(:), y(:), z(:), [], z(:));
 title ({'Default scatter3() plot', ...
         'constant size bubbles and color determined by Z'});

end

try
  if (~ exist ('scatter3_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter3_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter3_01.png" ... ');
      tic ();
      print ('-dpng', 'scatter3_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter3_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter3_01: %s\n', lasterr ());
  err_fid = fopen ('scatter3_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter3_02 ()
    
 clf;
 x = rand (20,1);  y = rand (20,1);  z = rand (20,1);
 scatter3 (x(:), y(:), z(:), 10, z(:), 's');
 title ({'scatter3() plot', ...
         'marker is square, size is 10, color determined by Z'});

end

try
  if (~ exist ('scatter3_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter3_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter3_02.png" ... ');
      tic ();
      print ('-dpng', 'scatter3_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter3_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter3_02: %s\n', lasterr ());
  err_fid = fopen ('scatter3_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter3_03 ()
    
 clf;
 x = rand (20,1);  y = rand (20,1);  z = rand (20,1);
 scatter3 (x(:), y(:), z(:), 20*z(:), [], 's');
 title ({'scatter3() plot', ...
         'marker is square, size is determined by Z'});

end

try
  if (~ exist ('scatter3_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter3_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter3_03.png" ... ');
      tic ();
      print ('-dpng', 'scatter3_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter3_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter3_03: %s\n', lasterr ());
  err_fid = fopen ('scatter3_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function scatter3_04 ()
    
 clf;
 x = rand (20,1);  y = rand (20,1);  z = rand (20,1);
 scatter3 (x(:), y(:), z(:), 20*z(:), z(:), 's');
 title ({'scatter3() plot', ...
         'marker is square, size and color determined by Z'});

end

try
  if (~ exist ('scatter3_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    scatter3_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "scatter3_04.png" ... ');
      tic ();
      print ('-dpng', 'scatter3_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "scatter3_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in scatter3_04: %s\n', lasterr ());
  err_fid = fopen ('scatter3_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function semilogx_01 ()
    
 clf;
 x = 1:0.01:10;
 y = (x .* (1 + rand (size (x)))) .^ 2;
 semilogx (y, x);
 title ({'semilogx() plot', 'X-axis is logarithmic'});

end

try
  if (~ exist ('semilogx_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    semilogx_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "semilogx_01.png" ... ');
      tic ();
      print ('-dpng', 'semilogx_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "semilogx_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in semilogx_01: %s\n', lasterr ());
  err_fid = fopen ('semilogx_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function semilogx_02 ()
    
 clf;
 x = logspace (-5, 1, 10);
 y = logspace (-5, 1, 10);

 subplot (1,2,1);
  semilogx (x, y);
  title ('semilogx (x, y)');

 subplot (1,2,2);
  semilogx (-x, y);
  title ('semilogx (-x, y)');

end

try
  if (~ exist ('semilogx_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    semilogx_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "semilogx_02.png" ... ');
      tic ();
      print ('-dpng', 'semilogx_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "semilogx_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in semilogx_02: %s\n', lasterr ());
  err_fid = fopen ('semilogx_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function semilogx_03 ()
    
 clf;
 x = logspace (-5, 1, 10);
 y = logspace (-5, 1, 10);

 subplot (1,2,1);
  semilogx (x, y);
  set (gca, 'xdir', 'reverse', 'activepositionproperty', 'outerposition');
  title ({'semilogx (x, y)', 'xdir = reversed'});

 subplot (1,2,2);
  semilogx (-x, y);
  set (gca, 'xdir', 'reverse', 'activepositionproperty', 'outerposition');
  title ({'semilogx (-x, y)', 'xdir = reversed'});

end

try
  if (~ exist ('semilogx_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    semilogx_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "semilogx_03.png" ... ');
      tic ();
      print ('-dpng', 'semilogx_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "semilogx_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in semilogx_03: %s\n', lasterr ());
  err_fid = fopen ('semilogx_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function semilogxerr_01 ()
    
 clf;
 x = exp (log (0.01):0.2:log (10));
 y = wblpdf (x, 2, 2);
 ey = 0.5*rand (size (y)) .* y;
 semilogxerr (x, y, ey, '#~x-');
 xlim (x([1, end]));
 title ({'semilogxerr(): semilogx() plot with errorbars', ...
         'X-axis is logarithmic'});

end

try
  if (~ exist ('semilogxerr_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    semilogxerr_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "semilogxerr_01.png" ... ');
      tic ();
      print ('-dpng', 'semilogxerr_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "semilogxerr_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in semilogxerr_01: %s\n', lasterr ());
  err_fid = fopen ('semilogxerr_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function semilogy_01 ()
    
 clf;
 x = 1:0.01:10;
 y = (x .* (1 + rand (size (x)))) .^ 2;
 semilogy (x, y);
 title ({'semilogx() plot', 'Y-axis is logarithmic'});

end

try
  if (~ exist ('semilogy_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    semilogy_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "semilogy_01.png" ... ');
      tic ();
      print ('-dpng', 'semilogy_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "semilogy_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in semilogy_01: %s\n', lasterr ());
  err_fid = fopen ('semilogy_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function semilogy_02 ()
    
 clf;
 x = logspace (-5, 1, 10);
 y = logspace (-5, 1, 10);

 subplot (2,1,1);
  semilogy (x, y);
  title ('semilogy (x, y)');

 subplot (2,1,2);
  semilogy (x, -y);
  title ('semilogy (x, -y)');

end

try
  if (~ exist ('semilogy_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    semilogy_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "semilogy_02.png" ... ');
      tic ();
      print ('-dpng', 'semilogy_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "semilogy_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in semilogy_02: %s\n', lasterr ());
  err_fid = fopen ('semilogy_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function semilogy_03 ()
    
 clf;
 x = logspace (-5, 1, 10);
 y = logspace (-5, 1, 10);

 subplot (2,1,1);
  semilogy (x, y);
  set (gca, 'ydir', 'reverse', 'activepositionproperty', 'outerposition');
  title ({'semilogy (x, y)', 'ydir = reversed'});

 subplot (2,1,2);
  semilogy (x, -y);
  set (gca, 'ydir', 'reverse', 'activepositionproperty', 'outerposition');
  title ({'semilogy (x, -y)', 'ydir = reversed'});

end

try
  if (~ exist ('semilogy_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    semilogy_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "semilogy_03.png" ... ');
      tic ();
      print ('-dpng', 'semilogy_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "semilogy_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in semilogy_03: %s\n', lasterr ());
  err_fid = fopen ('semilogy_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function semilogyerr_01 ()
    
 clf;
 x = 0.25:0.25:10;
 y = wblpdf (x, 4, 2);
 eyu = rand (size (y));
 eyl = 1.0 - 1./(1+eyu);
 semilogyerr (x, y, eyl.*y, eyu.*y, '~-d');
 xlim ([0 10]);
 title ({'semilogyerr(): semilogy() plot with errorbars', ...
         'Y-axis is logarithmic'});

end

try
  if (~ exist ('semilogyerr_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    semilogyerr_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "semilogyerr_01.png" ... ');
      tic ();
      print ('-dpng', 'semilogyerr_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "semilogyerr_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in semilogyerr_01: %s\n', lasterr ());
  err_fid = fopen ('semilogyerr_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shrinkfaces_01 ()
    
 clf;
 faces = [1 2 3; 1 3 4];
 vertices = [0 0; 1 0; 1 1; 0 1];
 patch ('Faces', faces, 'Vertices', vertices, 'FaceColor', 'none');
 fv = shrinkfaces (faces, vertices, 0.25);
 patch (fv);
 axis auto;   % Kludge required for Octave
 axis equal;
 title ('shrinkfaces() on triangular shapes');

end

try
  if (~ exist ('shrinkfaces_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    shrinkfaces_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shrinkfaces_01.png" ... ');
      tic ();
      print ('-dpng', 'shrinkfaces_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shrinkfaces_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shrinkfaces_01: %s\n', lasterr ());
  err_fid = fopen ('shrinkfaces_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shrinkfaces_02 ()
    
 clf;
 faces = [1 2 3 4; 5 6 7 8];
 vertices = [0 0; 1 0; 2 1; 1 1; 2 0; 3 0; 4 1; 3.5 1];
 patch ('Faces', faces, 'Vertices', vertices, 'FaceColor', 'none');
 fv = shrinkfaces (faces, vertices, 0.25);
 patch (fv);
 axis auto;   % Kludge required for Octave
 axis equal;
 grid on;
 title ('shrinkfaces() on rhomboid shapes');

end

try
  if (~ exist ('shrinkfaces_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    shrinkfaces_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shrinkfaces_02.png" ... ');
      tic ();
      print ('-dpng', 'shrinkfaces_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shrinkfaces_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shrinkfaces_02: %s\n', lasterr ());
  err_fid = fopen ('shrinkfaces_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shrinkfaces_03 ()
    
 clf;
 faces = [1 2 3 4];
 vertices = [-1 2; 0 0; 1 2; 0 1];
 patch ('Faces', faces, 'Vertices', vertices, 'FaceColor', 'none');
 fv = shrinkfaces (faces, vertices, 0.25);
 patch (fv);
 axis auto;   % Kludge required for Octave
 axis equal;
 grid on;
 title ('shrinkfaces() does not work on concave shapes');

end

try
  if (~ exist ('shrinkfaces_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    shrinkfaces_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shrinkfaces_03.png" ... ');
      tic ();
      print ('-dpng', 'shrinkfaces_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shrinkfaces_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shrinkfaces_03: %s\n', lasterr ());
  err_fid = fopen ('shrinkfaces_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shrinkfaces_04 ()
    
 clf;
 [phi r] = meshgrid (linspace (0, 1.5*pi, 16), linspace (1, 2, 4));
 tri = delaunay (phi(:), r(:));
 v = [r(:).*sin(phi(:)) r(:).*cos(phi(:))];
 p = patch ('Faces', tri, 'Vertices', v, 'FaceColor', 'none');
 fv = shrinkfaces (p);
 patch (fv);
 axis auto;   % Kludge required for Octave
 axis equal;
 grid on;
 title ('shrinkfaces() on 2-D complex shapes tesselated with triangles');

end

try
  if (~ exist ('shrinkfaces_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    shrinkfaces_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shrinkfaces_04.png" ... ');
      tic ();
      print ('-dpng', 'shrinkfaces_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shrinkfaces_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shrinkfaces_04: %s\n', lasterr ());
  err_fid = fopen ('shrinkfaces_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function shrinkfaces_05 ()
    
 clf;
 N = 10;  % N intervals per axis
 [x, y, z] = meshgrid (linspace (-4,4,N+1));
 val = x.^3 + y.^3 + z.^3;
 fv = isosurface (x, y, z, val, 3, z, 'noshare');

 p = patch ('Faces', fv.faces, 'Vertices', fv.vertices, 'FaceVertexCData', ...
            fv.facevertexcdata, 'FaceColor', 'interp', 'EdgeColor', 'black');
 axis auto;   % Kludge required for Octave
 axis equal;
 view (115, 30);
 drawnow;
 shrinkfaces (p, 0.6);
 title ('shrinkfaces() on 3-D complex shapes');

end

try
  if (~ exist ('shrinkfaces_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    shrinkfaces_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "shrinkfaces_05.png" ... ');
      tic ();
      print ('-dpng', 'shrinkfaces_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "shrinkfaces_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in shrinkfaces_05: %s\n', lasterr ());
  err_fid = fopen ('shrinkfaces_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function slice_01 ()
    
 clf;
 colormap ('default');
 [x, y, z] = meshgrid (linspace (-8, 8, 32));
 v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2));
 slice (x, y, z, v, [], 0, []);
 title ('slice() demo #1');

end

try
  if (~ exist ('slice_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    slice_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "slice_01.png" ... ');
      tic ();
      print ('-dpng', 'slice_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "slice_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in slice_01: %s\n', lasterr ());
  err_fid = fopen ('slice_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function slice_02 ()
    
 clf;
 colormap ('default');
 [x, y, z] = meshgrid (linspace (-8, 8, 32));
 v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2));
 [xi, yi] = meshgrid (linspace (-7, 7));
 zi = xi + yi;
 slice (x, y, z, v, xi, yi, zi);
 title ('slice() demo #2');

end

try
  if (~ exist ('slice_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    slice_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "slice_02.png" ... ');
      tic ();
      print ('-dpng', 'slice_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "slice_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in slice_02: %s\n', lasterr ());
  err_fid = fopen ('slice_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function smooth3_01 ()
    
 clf;
 data = rand (10, 10, 10);
 subplot (1, 2, 1);
  patch (isosurface (data, .5), ...
         'FaceColor', 'blue', 'EdgeColor', 'k');
  title ('Original data');
  view (3);
  smoothed_data = smooth3 (data);
 subplot (1, 2, 2);
  patch (isosurface (smoothed_data, .5), ...
         'FaceColor', 'blue', 'EdgeColor', 'k');
  title ('Smoothed data');
  view (3);

end

try
  if (~ exist ('smooth3_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    smooth3_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "smooth3_01.png" ... ');
      tic ();
      print ('-dpng', 'smooth3_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "smooth3_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in smooth3_01: %s\n', lasterr ());
  err_fid = fopen ('smooth3_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function sombrero_01 ()
    
 clf;
 colormap ('default');
 sombrero ();
 title ('sombrero() function');

end

try
  if (~ exist ('sombrero_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    sombrero_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "sombrero_01.png" ... ');
      tic ();
      print ('-dpng', 'sombrero_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "sombrero_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in sombrero_01: %s\n', lasterr ());
  err_fid = fopen ('sombrero_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stairs_01 ()
    
 clf;
 rand_1x10_data1 = [0.073, 0.455, 0.837, 0.124, 0.426, 0.781, 0.004, 0.024, 0.519, 0.698];
 y = rand_1x10_data1;
 stairs (y);
 title ('stairs() plot of y-data');

end

try
  if (~ exist ('stairs_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    stairs_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stairs_01.png" ... ');
      tic ();
      print ('-dpng', 'stairs_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stairs_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stairs_01: %s\n', lasterr ());
  err_fid = fopen ('stairs_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stairs_02 ()
    
 clf;
 x = 1:10;
 rand_1x10_data2 = [0.014, 0.460, 0.622, 0.394, 0.531, 0.378, 0.466, 0.788, 0.342, 0.893];
 y = rand_1x10_data2;
 [xs, ys] = stairs (x, y);
 plot (xs, ys);
 title ('plot() of stairs() generated data');

end

try
  if (~ exist ('stairs_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    stairs_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stairs_02.png" ... ');
      tic ();
      print ('-dpng', 'stairs_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stairs_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stairs_02: %s\n', lasterr ());
  err_fid = fopen ('stairs_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stairs_03 ()
    
 clf;
 stairs (1:9, '-o');
 title ('stairs() plot with linespec to modify marker');

end

try
  if (~ exist ('stairs_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    stairs_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stairs_03.png" ... ');
      tic ();
      print ('-dpng', 'stairs_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stairs_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stairs_03: %s\n', lasterr ());
  err_fid = fopen ('stairs_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stairs_04 ()
    
 clf;
 stairs (9:-1:1, 'marker', 's', 'markersize', 10, 'markerfacecolor', 'm');
 title ('stairs() plot with prop/val pairs to modify appearance');

end

try
  if (~ exist ('stairs_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    stairs_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stairs_04.png" ... ');
      tic ();
      print ('-dpng', 'stairs_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stairs_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stairs_04: %s\n', lasterr ());
  err_fid = fopen ('stairs_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stairs_05 ()
    
 clf;
 N = 11;
 x = 0:(N-1);
 y = rand (1, N);
 hs = stairs (x(1), y(1));
 axis ([1, N-1 0, 1]);
 title ('stairs plot data modified through handle');
 for k = 2:N
   set (hs, 'xdata', x(1:k), 'ydata', y(1:k));
   drawnow ();
   pause (0.2);
 end

end

try
  if (~ exist ('stairs_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    stairs_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stairs_05.png" ... ');
      tic ();
      print ('-dpng', 'stairs_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stairs_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stairs_05: %s\n', lasterr ());
  err_fid = fopen ('stairs_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stem_01 ()
    
 clf;
 y = 1:10;
 stem (y);
 title ('stem plot of y-values only');

end

try
  if (~ exist ('stem_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    stem_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stem_01.png" ... ');
      tic ();
      print ('-dpng', 'stem_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stem_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stem_01: %s\n', lasterr ());
  err_fid = fopen ('stem_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stem_02 ()
    
 clf;
 x = 1:10;
 y = 2*x;
 stem (x, y);
 title ('stem plot of x and y-values');

end

try
  if (~ exist ('stem_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    stem_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stem_02.png" ... ');
      tic ();
      print ('-dpng', 'stem_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stem_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stem_02: %s\n', lasterr ());
  err_fid = fopen ('stem_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stem_03 ()
    
 clf;
 x = 1:10;
 y = 2*x;
 h = stem (x, y, 'r');
 title ('stem plot with modified color');

end

try
  if (~ exist ('stem_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    stem_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stem_03.png" ... ');
      tic ();
      print ('-dpng', 'stem_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stem_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stem_03: %s\n', lasterr ());
  err_fid = fopen ('stem_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stem_04 ()
    
 clf;
 x = 1:10;
 y = 2*x;
 h = stem (x, y, '-.k');
 title ('stem plot with modified line style and color');

end

try
  if (~ exist ('stem_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    stem_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stem_04.png" ... ');
      tic ();
      print ('-dpng', 'stem_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stem_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stem_04: %s\n', lasterr ());
  err_fid = fopen ('stem_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stem_05 ()
    
 clf;
 x = 1:10;
 y = 2*x;
 h = stem (x, y, '-.ks');
 title ('stem plot with modified line style, color, and marker');

end

try
  if (~ exist ('stem_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    stem_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stem_05.png" ... ');
      tic ();
      print ('-dpng', 'stem_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stem_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stem_05: %s\n', lasterr ());
  err_fid = fopen ('stem_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stem_06 ()
    
 clf;
 x = 1:10;
 y = 2*x;
 h = stem (x, y, 'filled');
 title ('stem plot with "filled" markers');

end

try
  if (~ exist ('stem_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    stem_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stem_06.png" ... ');
      tic ();
      print ('-dpng', 'stem_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stem_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stem_06: %s\n', lasterr ());
  err_fid = fopen ('stem_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stem_07 ()
    
 clf;
 x = 1:10;
 y = 2*x;
 h = stem (x, y, 'markerfacecolor', [1 0 1]);
 title ('stem plot modified with property/value pair');

end

try
  if (~ exist ('stem_07.png', 'file'))
    rand ('seed', 1);
    tic ();
    stem_07 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stem_07.png" ... ');
      tic ();
      print ('-dpng', 'stem_07.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stem_07.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stem_07: %s\n', lasterr ());
  err_fid = fopen ('stem_07.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stem_08 ()
    
 clf;
 x = (0 : 10)';
 y = [sin(x), cos(x)];
 h = stem (x, y);
 set (h(2), 'color', 'g');
 set (h(1), 'basevalue', -0.75);
 title ('stem plots modified through hggroup handle');

end

try
  if (~ exist ('stem_08.png', 'file'))
    rand ('seed', 1);
    tic ();
    stem_08 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stem_08.png" ... ');
      tic ();
      print ('-dpng', 'stem_08.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stem_08.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stem_08: %s\n', lasterr ());
  err_fid = fopen ('stem_08.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stem_09 ()
    
 clf;
 N = 11;
 x = 0:(N-1);
 y = rand (1, N);
 hs = stem (x(1), y(1));
 set (gca (), 'xlim', [1, N-1], 'ylim', [0, 1]);
 title ('stem plot data modified through hggroup handle');
 for k=2:N
   set (hs, 'xdata', x(1:k), 'ydata', y(1:k));
   drawnow ();
   pause (0.2);
 end

end

try
  if (~ exist ('stem_09.png', 'file'))
    rand ('seed', 1);
    tic ();
    stem_09 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stem_09.png" ... ');
      tic ();
      print ('-dpng', 'stem_09.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stem_09.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stem_09: %s\n', lasterr ());
  err_fid = fopen ('stem_09.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stem3_01 ()
    
 clf;
 theta = 0:0.2:6;
 stem3 (cos (theta), sin (theta), theta);
 title ('stem3() plot');

end

try
  if (~ exist ('stem3_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    stem3_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stem3_01.png" ... ');
      tic ();
      print ('-dpng', 'stem3_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stem3_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stem3_01: %s\n', lasterr ());
  err_fid = fopen ('stem3_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stemleaf_01 ()
    
 %% Unsorted plot:
 x = [-22 12 -28 52  39 -2 12 10 11 11 42 38 44 18 44];
 stemleaf (x, 'Unsorted plot');

end

try
  if (~ exist ('stemleaf_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    stemleaf_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stemleaf_01.png" ... ');
      tic ();
      print ('-dpng', 'stemleaf_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stemleaf_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stemleaf_01: %s\n', lasterr ());
  err_fid = fopen ('stemleaf_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stemleaf_02 ()
    
 %% Sorted leaves:
 x = [-22 12 -28 52  39 -2 12 10 11 11 42 38 44 18 44];
 y = sort (x);
 stemleaf (y, 'Sorted leaves');

end

try
  if (~ exist ('stemleaf_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    stemleaf_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stemleaf_02.png" ... ');
      tic ();
      print ('-dpng', 'stemleaf_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stemleaf_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stemleaf_02: %s\n', lasterr ());
  err_fid = fopen ('stemleaf_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stemleaf_03 ()
    
 %% Sorted leaves (large dataset):
 x = [-22 12 -28 52  39 -2 12 10 11 11 42 38 44 18 44 37 113 124 37 48     ...
      127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119   ...
      58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 ...
      121 58 114 126 53 114 96 25 109 7 31 141 46 -13 71 43 117 116 27 7   ...
      68 40 31 115 124 42 128 52 71 118 117 38 27 106 33 117 116 111 40    ...
      119 47 105 57 122 109 124 115 43 120 43 27 27 18 28 48 125 107 114   ...
      34 133 45 120 30 127 31 116 146 21 23 30 10 20 21 30 0 100 110 1 20  ...
      0];
 y = sort (x);
 stemleaf (y, 'Sorted leaves (large dataset)');

end

try
  if (~ exist ('stemleaf_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    stemleaf_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stemleaf_03.png" ... ');
      tic ();
      print ('-dpng', 'stemleaf_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stemleaf_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stemleaf_03: %s\n', lasterr ());
  err_fid = fopen ('stemleaf_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function stemleaf_04 ()
    
 %% Gaussian leaves:
 x = fix (30 * randn (300,1));
 stemleaf (x, 'Gaussian leaves');

end

try
  if (~ exist ('stemleaf_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    stemleaf_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "stemleaf_04.png" ... ');
      tic ();
      print ('-dpng', 'stemleaf_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "stemleaf_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in stemleaf_04: %s\n', lasterr ());
  err_fid = fopen ('stemleaf_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function surf_01 ()
    
 clf;
 colormap ('default');
 Z = peaks ();
 surf (Z);
 title ({'surf() plot of peaks() function'; 'color determined by height Z'});

end

try
  if (~ exist ('surf_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    surf_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "surf_01.png" ... ');
      tic ();
      print ('-dpng', 'surf_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "surf_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in surf_01: %s\n', lasterr ());
  err_fid = fopen ('surf_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function surf_02 ()
    
 clf;
 colormap ('default');
 Z = sombrero ();
 [Fx,Fy] = gradient (Z);
 surf (Z, Fx+Fy);
 shading interp;
 title ({'surf() plot of peaks() function'; ...
         'facecolor is interpolated, color determined by gradient of Z'});

end

try
  if (~ exist ('surf_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    surf_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "surf_02.png" ... ');
      tic ();
      print ('-dpng', 'surf_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "surf_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in surf_02: %s\n', lasterr ());
  err_fid = fopen ('surf_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function surf_03 ()
    
 clf;
 colormap ('default');
 [X,Y,Z] = sombrero ();
 [~,Fy] = gradient (Z);
 surf (X, Y, Z, Fy);
 shading interp;
 title ({'surf() plot of peaks() function'; ...
         'facecolor is interpolated, color determined by Y-gradient of Z'});

end

try
  if (~ exist ('surf_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    surf_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "surf_03.png" ... ');
      tic ();
      print ('-dpng', 'surf_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "surf_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in surf_03: %s\n', lasterr ());
  err_fid = fopen ('surf_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function surfc_01 ()
    
 clf;
 colormap ('default');
 Z = peaks ();
 surfc (Z);
 title ('surfc() combines surf/contour plots');

end

try
  if (~ exist ('surfc_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    surfc_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "surfc_01.png" ... ');
      tic ();
      print ('-dpng', 'surfc_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "surfc_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in surfc_01: %s\n', lasterr ());
  err_fid = fopen ('surfc_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function surfc_02 ()
    
 clf;
 colormap ('default');
 Z = sombrero ();
 [Fx,Fy] = gradient (Z);
 surfc (Z, Fx+Fy);
 shading interp;
 title ({'surfc() plot of sombrero() function'; ...
         'facecolor is interpolated, color determined by gradient of Z'});

end

try
  if (~ exist ('surfc_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    surfc_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "surfc_02.png" ... ');
      tic ();
      print ('-dpng', 'surfc_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "surfc_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in surfc_02: %s\n', lasterr ());
  err_fid = fopen ('surfc_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function surfc_03 ()
    
 clf;
 colormap ('default');
 [X,Y,Z] = sombrero ();
 [~,Fy] = gradient (Z);
 surfc (X,Y,Z,Fy);
 shading interp;
 title ({'surfc() plot of peaks() function'; ...
         'facecolor is interpolated, color determined by Y-gradient of Z'});

end

try
  if (~ exist ('surfc_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    surfc_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "surfc_03.png" ... ');
      tic ();
      print ('-dpng', 'surfc_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "surfc_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in surfc_03: %s\n', lasterr ());
  err_fid = fopen ('surfc_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function surfl_01 ()
    
 clf;
 [X,Y,Z] = sombrero ();
 colormap (copper (64));
 surfl (X,Y,Z);
 shading interp;
 title ('surfl() with defaults');

end

try
  if (~ exist ('surfl_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    surfl_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "surfl_01.png" ... ');
      tic ();
      print ('-dpng', 'surfl_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "surfl_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in surfl_01: %s\n', lasterr ());
  err_fid = fopen ('surfl_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function surfl_02 ()
    
 clf;
 [X,Y,Z] = sombrero ();
 colormap (copper (64));
 surfl (X,Y,Z, [62.50,30], [0.2 0.6 0.4 25]);
 shading interp;
 title ('surfl() with lighting vector and material properties');

end

try
  if (~ exist ('surfl_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    surfl_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "surfl_02.png" ... ');
      tic ();
      print ('-dpng', 'surfl_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "surfl_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in surfl_02: %s\n', lasterr ());
  err_fid = fopen ('surfl_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function surfnorm_01 ()
    
 clf;
 colormap ('default');
 surfnorm (peaks (19));
 shading faceted;
 title ({'surfnorm() shows surface and normals at each vertex', ...
         'peaks() function with 19 faces'});

end

try
  if (~ exist ('surfnorm_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    surfnorm_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "surfnorm_01.png" ... ');
      tic ();
      print ('-dpng', 'surfnorm_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "surfnorm_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in surfnorm_01: %s\n', lasterr ());
  err_fid = fopen ('surfnorm_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function surfnorm_02 ()
    
 clf;
 colormap ('default');
 [x, y, z] = sombrero (10);
 surfnorm (x, y, z);
 title ({'surfnorm() shows surface and normals at each vertex', ...
         'sombrero() function with 10 faces'});

end

try
  if (~ exist ('surfnorm_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    surfnorm_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "surfnorm_02.png" ... ');
      tic ();
      print ('-dpng', 'surfnorm_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "surfnorm_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in surfnorm_02: %s\n', lasterr ());
  err_fid = fopen ('surfnorm_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function tetramesh_01 ()
    
 clf;
 d = [-1 1];
 [x,y,z] = meshgrid (d, d, d);
 x = [x(:); 0];
 y = [y(:); 0];
 z = [z(:); 0];
 tetra = delaunay (x, y, z);
 X = [x(:) y(:) z(:)];
 colormap (jet (64));
 h = tetramesh (tetra, X);
 set (h(1:2:end), 'visible', 'off');
 axis equal;
 view (30, 20);
 title ({'tetramesh() plot', ...
         'colormap = jet (64), every other tetrahedron invisible'});

end

try
  if (~ exist ('tetramesh_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    tetramesh_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "tetramesh_01.png" ... ');
      tic ();
      print ('-dpng', 'tetramesh_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "tetramesh_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in tetramesh_01: %s\n', lasterr ());
  err_fid = fopen ('tetramesh_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function tetramesh_02 ()
    
 clf;
 d = [-1 1];
 [x,y,z] = meshgrid (d, d, d);
 x = [x(:); 0];
 y = [y(:); 0];
 z = [z(:); 0];
 tetra = delaunay (x, y, z);
 X = [x(:) y(:) z(:)];
 colormap (gray (256));
 tetramesh (tetra, X, 21:20:241, 'EdgeColor', 'w');
 axis equal;
 view (30, 20);
 title ({'tetramesh() plot', ...
         'colormap = gray (256) with white edges'});

end

try
  if (~ exist ('tetramesh_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    tetramesh_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "tetramesh_02.png" ... ');
      tic ();
      print ('-dpng', 'tetramesh_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "tetramesh_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in tetramesh_02: %s\n', lasterr ());
  err_fid = fopen ('tetramesh_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function trimesh_01 ()
    
 clf;
 colormap ('default');
 old_state = rand ('state');
 restore_state = onCleanup (@() rand ('state', old_state));
 rand ('state', 10);
 N = 10;
 x = 3 - 6 * rand (N, N);
 y = 3 - 6 * rand (N, N);
 z = peaks (x, y);
 tri = delaunay (x(:), y(:));
 trimesh (tri, x(:), y(:), z(:));
 title ('trimesh() plot of sparsely-sampled peaks() function');

end

try
  if (~ exist ('trimesh_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    trimesh_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "trimesh_01.png" ... ');
      tic ();
      print ('-dpng', 'trimesh_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "trimesh_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in trimesh_01: %s\n', lasterr ());
  err_fid = fopen ('trimesh_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function triplot_01 ()
    
 clf;
 old_state = rand ('state');
 restore_state = onCleanup (@() rand ('state', old_state));
 rand ('state', 2);
 N = 20;
 x = rand (N, 1);
 y = rand (N, 1);
 tri = delaunay (x, y);
 triplot (tri, x, y);
 title ('triplot() of random 2-D Delaunay triangulation');

end

try
  if (~ exist ('triplot_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    triplot_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "triplot_01.png" ... ');
      tic ();
      print ('-dpng', 'triplot_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "triplot_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in triplot_01: %s\n', lasterr ());
  err_fid = fopen ('triplot_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function trisurf_01 ()
    
 clf;
 colormap ('default');
 N = 31;
 [x, y] = meshgrid (1:N);
 tri = delaunay (x(:), y(:));
 z = peaks (N);
 h = trisurf (tri, x, y, z, 'facecolor', 'flat');
 axis tight;
 zlim auto;
 title ({'trisurf() of peaks() function', 'facecolor = "flat"'});

end

try
  if (~ exist ('trisurf_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    trisurf_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "trisurf_01.png" ... ');
      tic ();
      print ('-dpng', 'trisurf_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "trisurf_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in trisurf_01: %s\n', lasterr ());
  err_fid = fopen ('trisurf_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function trisurf_02 ()
    
 clf;
 colormap ('default');
 N = 31;
 [x, y] = meshgrid (1:N);
 tri = delaunay (x(:), y(:));
 z = peaks (N);
 h = trisurf (tri, x, y, z, 'facecolor', 'interp');
 axis tight;
 zlim auto;
 title ({'trisurf() of peaks() function', 'facecolor = "interp"'});

end

try
  if (~ exist ('trisurf_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    trisurf_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "trisurf_02.png" ... ');
      tic ();
      print ('-dpng', 'trisurf_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "trisurf_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in trisurf_02: %s\n', lasterr ());
  err_fid = fopen ('trisurf_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function trisurf_03 ()
    
 clf;
 colormap ('default');
 old_state = rand ('state');
 restore_state = onCleanup (@() rand ('state', old_state));
 rand ('state', 10);
 N = 10;
 x = 3 - 6 * rand (N, N);
 y = 3 - 6 * rand (N, N);
 z = peaks (x, y);
 tri = delaunay (x(:), y(:));
 trisurf (tri, x(:), y(:), z(:));
 title ('trisurf() of sparsely-sampled triangulation of peaks()');

end

try
  if (~ exist ('trisurf_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    trisurf_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "trisurf_03.png" ... ');
      tic ();
      print ('-dpng', 'trisurf_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "trisurf_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in trisurf_03: %s\n', lasterr ());
  err_fid = fopen ('trisurf_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function trisurf_04 ()
    
 clf;
 colormap ('default');
 x = rand (100, 1);
 y = rand (100, 1);
 z = x.^2 + y.^2;
 tri = delaunay (x, y);
 trisurf (tri, x, y, z);
 title ({'trisurf() of random data', 'default "facecolor" = "flat", "edgecolor" = "black"'});

end

try
  if (~ exist ('trisurf_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    trisurf_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "trisurf_04.png" ... ');
      tic ();
      print ('-dpng', 'trisurf_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "trisurf_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in trisurf_04: %s\n', lasterr ());
  err_fid = fopen ('trisurf_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function trisurf_05 ()
    
 clf;
 colormap ('default');
 x = rand (100, 1);
 y = rand (100, 1);
 z = x.^2 + y.^2;
 tri = delaunay (x, y);
 trisurf (tri, x, y, z, 'facecolor', 'interp');
 title ({'trisurf() of random data', '"facecolor" = "interp"'});

end

try
  if (~ exist ('trisurf_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    trisurf_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "trisurf_05.png" ... ');
      tic ();
      print ('-dpng', 'trisurf_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "trisurf_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in trisurf_05: %s\n', lasterr ());
  err_fid = fopen ('trisurf_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function trisurf_06 ()
    
 clf;
 colormap ('default');
 x = rand (100, 1);
 y = rand (100, 1);
 z = x.^2 + y.^2;
 tri = delaunay (x, y);
 trisurf (tri, x, y, z, 'facecolor', 'interp', 'edgecolor', 'w');
 title ({'trisurf() of random data', '"facecolor" = "interp", "edgecolor" = "white"'});

end

try
  if (~ exist ('trisurf_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    trisurf_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "trisurf_06.png" ... ');
      tic ();
      print ('-dpng', 'trisurf_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "trisurf_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in trisurf_06: %s\n', lasterr ());
  err_fid = fopen ('trisurf_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function waterfall_01 ()
    
 clf;
 colormap ('default');
 Z = peaks ();
 waterfall (Z);
 title ('waterfall() plot of peaks() function');

end

try
  if (~ exist ('waterfall_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    waterfall_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "waterfall_01.png" ... ');
      tic ();
      print ('-dpng', 'waterfall_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "waterfall_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in waterfall_01: %s\n', lasterr ());
  err_fid = fopen ('waterfall_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function waterfall_02 ()
    
 clf;
 colormap ('default');
 Z = peaks ();
 subplot (1,2,1)
  meshz (Z);
  daspect ([2.5, 2.5, 1]);
  title ('meshz() plot');
 subplot (1,2,2)
  waterfall (Z);
  daspect ([2.5, 2.5, 1]);
  title ('waterfall() plot');

end

try
  if (~ exist ('waterfall_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    waterfall_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "waterfall_02.png" ... ');
      tic ();
      print ('-dpng', 'waterfall_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "waterfall_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in waterfall_02: %s\n', lasterr ());
  err_fid = fopen ('waterfall_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

close all

function axes_01 ()
    
 clf;
 x = -10:10;
 plot (x,x, x,-x);
 set (gca, 'yscale', 'log');
 legend ({'x >= 1', 'x <= 1'}, 'location', 'north');
 title ({'log axes discard negative data', 'ylim = [1, 10]'});

end

try
  if (~ exist ('axes_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    axes_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axes_01.png" ... ');
      tic ();
      print ('-dpng', 'axes_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axes_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axes_01: %s\n', lasterr ());
  err_fid = fopen ('axes_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axes_02 ()
    
 clf;
 x = -10:0.1:10;
 y = sin (x)./(1 + abs (x)) + 0.1*x - 0.4;
 plot (x, y);
 set (gca, 'xaxislocation', 'origin');
 set (gca, 'yaxislocation', 'origin');
 box off;
 title ({'no plot box', 'xaxislocation = origin, yaxislocation = origin'});

end

try
  if (~ exist ('axes_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    axes_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axes_02.png" ... ');
      tic ();
      print ('-dpng', 'axes_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axes_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axes_02: %s\n', lasterr ());
  err_fid = fopen ('axes_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axes_03 ()
    
 clf;
 x = -10:0.1:10;
 y = sin (x)./(1+abs (x)) + 0.1*x - 0.4;
 plot (x, y);
 set (gca, 'xaxislocation', 'origin');
 set (gca, 'yaxislocation', 'left');
 box off;
 title ({'no plot box', 'xaxislocation = origin, yaxislocation = left'});

end

try
  if (~ exist ('axes_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    axes_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axes_03.png" ... ');
      tic ();
      print ('-dpng', 'axes_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axes_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axes_03: %s\n', lasterr ());
  err_fid = fopen ('axes_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axes_04 ()
    
 clf;
 x = -10:0.1:10;
 y = sin (x)./(1+abs (x)) + 0.1*x - 0.4;
 plot (x, y);
 title ('no plot box');
 set (gca, 'xaxislocation', 'origin');
 set (gca, 'yaxislocation', 'right');
 box off;
 title ({'no plot box', 'xaxislocation = origin, yaxislocation = right'});

end

try
  if (~ exist ('axes_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    axes_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axes_04.png" ... ');
      tic ();
      print ('-dpng', 'axes_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axes_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axes_04: %s\n', lasterr ());
  err_fid = fopen ('axes_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axes_05 ()
    
 clf;
 x = -10:0.1:10;
 y = sin (x)./(1+abs (x)) + 0.1*x - 0.4;
 plot (x, y);
 set (gca, 'xaxislocation', 'bottom');
 set (gca, 'yaxislocation', 'origin');
 box off;
 title ({'no plot box', 'xaxislocation = bottom, yaxislocation = origin'});

end

try
  if (~ exist ('axes_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    axes_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axes_05.png" ... ');
      tic ();
      print ('-dpng', 'axes_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axes_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axes_05: %s\n', lasterr ());
  err_fid = fopen ('axes_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function axes_06 ()
    
 clf;
 x = -10:0.1:10;
 y = sin (x)./(1+abs (x)) + 0.1*x - 0.4;
 plot (x, y);
 set (gca, 'xaxislocation', 'top');
 set (gca, 'yaxislocation', 'origin');
 box off;
 title ({'no plot box', 'xaxislocation = top, yaxislocation = origin'});

end

try
  if (~ exist ('axes_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    axes_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "axes_06.png" ... ');
      tic ();
      print ('-dpng', 'axes_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "axes_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in axes_06: %s\n', lasterr ());
  err_fid = fopen ('axes_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function copyobj_01 ()
    
 hobj = clf;
 set (hobj, 'name', 'Original', 'numbertitle', 'off');
 hold on;
 x = 1:10;
 y = x.^2;
 dy = 2 * (.2 * x);
 y2 = (x - 3).^2;
 hg = errorbar (x, y, dy);
 set (hg, 'marker', '^', 'markerfacecolor', rand (1,3));
 plot (x, y2, 'ok-');
 legend ('errorbar', 'line');
 drawnow ();
 pos = get (hobj, 'position');
 scrn = get (0, 'screensize');
 set (hobj, 'position', [scrn(3)/2-pos(3)-10, scrn(4)/2-pos(4)/2, pos(3:4)]);
 drawnow ();
 hnew = copyobj (hobj);
 drawnow ();
 set (hnew, 'name', 'Copyobj');
 drawnow ();
 set (hnew, 'position', [scrn(3)/2, scrn(4)/2-pos(4)/2, pos(3:4)]);
 drawnow ();

end

try
  if (~ exist ('copyobj_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    copyobj_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "copyobj_01.png" ... ');
      tic ();
      print ('-dpng', 'copyobj_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "copyobj_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in copyobj_01: %s\n', lasterr ());
  err_fid = fopen ('copyobj_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function copyobj_02 ()
    
 hobj = clf;
 set (hobj, 'name', 'Original', 'numbertitle', 'off');
 subplot (2,2,1);
  hold on;
  contourf (rand (10, 10));
  colorbar ();
 subplot (2,2,2);
  quiver (rand (10, 10), rand (10, 10));
 subplot (2,2,3);
  colormap (jet (64));
  hold on;
  sombrero ();
  colorbar ('peer', gca, 'NorthOutside');
 subplot (2,2,4);
  imagesc (rand (30, 30));
  text (15, 15, 'Rotated text', ...
        'HorizontAlalignment', 'Center', 'Rotation', 30);
 drawnow ();
 pos = get (hobj, 'position');
 scrn = get (0, 'screensize');
 set (hobj, 'position', [scrn(3)/2-pos(3)-10, scrn(4)/2-pos(4)/2, pos(3:4)]);
 drawnow ();
 hnew = copyobj (hobj);
 drawnow ();
 set (hnew, 'name', 'Copyobj');
 drawnow ();
 set (hnew, 'position', [scrn(3)/2, scrn(4)/2-pos(4)/2, pos(3:4)]);
 drawnow ();

end

try
  if (~ exist ('copyobj_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    copyobj_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "copyobj_02.png" ... ');
      tic ();
      print ('-dpng', 'copyobj_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "copyobj_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in copyobj_02: %s\n', lasterr ());
  err_fid = fopen ('copyobj_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function copyobj_03 ()
    
 hobj = clf;
 set (hobj, 'name', 'Original', 'numbertitle', 'off');
 x = 0:0.1:2*pi;
 y1 = sin (x);
 y2 = exp (x - 1);
 ax = plotyy (x,y1, x-1,y2, @plot, @semilogy);
 xlabel ('X');
 ylabel (ax(1), 'Axis 1');
 ylabel (ax(2), 'Axis 2');
 lcolor = get (gca, 'ColorOrder')(1,:);
 rcolor = get (gca, 'ColorOrder')(2,:);
 text (0.5, 0.5, 'Left Axis', ...
       'color', lcolor, 'horizontalalignment', 'center', 'parent', ax(1));
 text (4.5, 80, 'Right Axis', ...
       'color', rcolor, 'horizontalalignment', 'center', 'parent', ax(2));
 title ({'plotyy() example'; 'left axis uses @plot, right axis uses @semilogy'});
 drawnow ();
 pos = get (hobj, 'position');
 scrn = get (0, 'screensize');
 set (hobj, 'position', [scrn(3)/2-pos(3)-10, scrn(4)/2-pos(4)/2, pos(3:4)]);
 drawnow ();
 hnew = copyobj (hobj);
 drawnow ();
 set (hnew, 'name', 'Copyobj');
 drawnow ();
 set (hnew, 'position', [scrn(3)/2, scrn(4)/2-pos(4)/2, pos(3:4)]);
 drawnow ();

end

try
  if (~ exist ('copyobj_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    copyobj_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "copyobj_03.png" ... ');
      tic ();
      print ('-dpng', 'copyobj_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "copyobj_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in copyobj_03: %s\n', lasterr ());
  err_fid = fopen ('copyobj_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function hold_01 ()
    
 clf;
 t = linspace (0, 2*pi, 100);
 plot (t, sin (t));
 hold on;
 plot (t, cos (t));
 title ({'hold on', '2 plots shown on same graph'});
 hold off;

end

try
  if (~ exist ('hold_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    hold_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "hold_01.png" ... ');
      tic ();
      print ('-dpng', 'hold_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "hold_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in hold_01: %s\n', lasterr ());
  err_fid = fopen ('hold_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function hold_02 ()
    
 clf;
 A = rand (100);
 [X, Y] = find (A > 0.95);
 imshow (A);
 hold on;
 plot (X, Y, 'o');
 hold off;
 title ('hold with image and plot');

end

try
  if (~ exist ('hold_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    hold_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "hold_02.png" ... ');
      tic ();
      print ('-dpng', 'hold_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "hold_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in hold_02: %s\n', lasterr ());
  err_fid = fopen ('hold_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function hold_03 ()
    
 clf;
 colormap ('default');
 hold on;
 imagesc (1 ./ hilb (4));
 plot (1:4, '-s');
 title ('hold with image and plot');
 hold off;

end

try
  if (~ exist ('hold_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    hold_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "hold_03.png" ... ');
      tic ();
      print ('-dpng', 'hold_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "hold_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in hold_03: %s\n', lasterr ());
  err_fid = fopen ('hold_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function hold_04 ()
    
 clf;
 colormap ('default');
 hold on;
 imagesc (1 ./ hilb (2));
 imagesc (1 ./ hilb (4));
 title ({'hold with two images', 'only second image is visible'});
 hold off;

end

try
  if (~ exist ('hold_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    hold_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "hold_04.png" ... ');
      tic ();
      print ('-dpng', 'hold_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "hold_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in hold_04: %s\n', lasterr ());
  err_fid = fopen ('hold_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function hold_05 ()
    
 clf;
 colormap ('default');
 hold on;
 plot (1:4, '-s');
 imagesc (1 ./ hilb (4));
 title ({'hold with plot and image', 'only image is visible'});
 hold off;

end

try
  if (~ exist ('hold_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    hold_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "hold_05.png" ... ');
      tic ();
      print ('-dpng', 'hold_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "hold_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in hold_05: %s\n', lasterr ());
  err_fid = fopen ('hold_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function hold_06 ()
    
 clf;
 colormap ('default');
 t = linspace (-3, 3, 50);
 [x, y] = meshgrid (t, t);
 z = peaks (x, y);
 contourf (x, y, z, 10);
 hold on;
 plot (x(:), y(:), '^');
 patch ([-1.0 1.0 1.0 -1.0 -1.0], [-1.0 -1.0 1.0 1.0 -1.0], 'red');
 xlim ([-2.0 2.0]);
 ylim ([-2.0 2.0]);
 colorbar ('SouthOutside');
 title ('hold with line, surface, and patch objects');

end

try
  if (~ exist ('hold_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    hold_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "hold_06.png" ... ');
      tic ();
      print ('-dpng', 'hold_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "hold_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in hold_06: %s\n', lasterr ());
  err_fid = fopen ('hold_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function printd_01 ()
    
 r2 = char ( ...
 'stem step: 10, data: unsorted.', ...
 'Hinges:    lo: 12, hi: 42'     , ...
 '   1 | 22118'                  , ...
 '   2 | 28'                     , ...
 '   3 | 98'                     , ...
 '   4 | 244'                    , ...
 '   5 | 2'                      );
 printd (r2, 'test_p.txt');
 system ('cat test_p.txt');
 delete ('test_p.txt');

end

try
  if (~ exist ('printd_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    printd_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "printd_01.png" ... ');
      tic ();
      print ('-dpng', 'printd_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "printd_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in printd_01: %s\n', lasterr ());
  err_fid = fopen ('printd_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function refreshdata_01 ()
    
 clf;
 x = 0:0.1:10;
 y = sin (x);
 plot (x, y, 'ydatasource', 'y');
 title ('refreshdata() showing moving sine curve');
 axis manual;
 for i = 1 : 100
   pause (0);
   y = sin (x + 0.1 * i);
   refreshdata (gcf, 'caller');
 end

end

try
  if (~ exist ('refreshdata_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    refreshdata_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "refreshdata_01.png" ... ');
      tic ();
      print ('-dpng', 'refreshdata_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "refreshdata_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in refreshdata_01: %s\n', lasterr ());
  err_fid = fopen ('refreshdata_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function subplot_01 ()
    
 clf;
 r = 3;
 c = 3;
 fmt = {'horizontalalignment', 'center', 'verticalalignment', 'middle'};
 for n = 1 : r*c
   subplot (r, c, n);
    xlabel (sprintf ('xlabel #%d', n));
    ylabel (sprintf ('ylabel #%d', n));
    title (sprintf ('title #%d', n));
    text (0.5, 0.5, sprintf ('subplot(%d,%d,%d)', r, c, n), fmt{:});
    axis ([0 1 0 1]);
 end
 subplot (r, c, 1:3);
  xlabel (sprintf ('xlabel #%d:%d', 1, 3));
  ylabel (sprintf ('ylabel #%d:%d', 1, 3));
  title (sprintf ('title #%d:%d', 1, 3));
  text (0.5, 0.5, sprintf ('subplot(%d,%d,%d:%d)', r, c, 1, 3), fmt{:});
 axis ([0 1 0 1]);

end

try
  if (~ exist ('subplot_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    subplot_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "subplot_01.png" ... ');
      tic ();
      print ('-dpng', 'subplot_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "subplot_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in subplot_01: %s\n', lasterr ());
  err_fid = fopen ('subplot_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function subplot_02 ()
    
 clf;
 x = 0:1;
 for n = 1:4
   subplot (2,2,n, 'align');
    plot (x, x);
    xlabel (sprintf ('xlabel (2,2,%d)', n));
    ylabel (sprintf ('ylabel (2,2,%d)', n));
    title (sprintf ('title (2,2,%d)', n));
 end
 subplot (1,2,1, 'align');
  plot (x, x);
  xlabel ('xlabel (1,2,1)');
  ylabel ('ylabel (1,2,1)');
  title ('title (1,2,1)');

end

try
  if (~ exist ('subplot_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    subplot_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "subplot_02.png" ... ');
      tic ();
      print ('-dpng', 'subplot_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "subplot_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in subplot_02: %s\n', lasterr ());
  err_fid = fopen ('subplot_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function subplot_03 ()
    
 clf;
 x = 0:10;
 ax(1) = subplot (221);
 set (ax(1), 'tag', '1');
 plot (x, rand (3, 11));
 title ('x & y labels & ticklabels');
 xlabel xlabel;
 ylabel ylabel;
 ax(2) = subplot (222);
 set (ax(2), 'tag', '2');
 plot (x, rand (3, 11));
 title ('no labels');
 axis ('nolabel','tic');
 ax(3) = subplot (223);
 set (ax(3), 'tag', '3');
 plot (x, rand (3, 11));
 title ('no labels');
 axis ('nolabel','tic');
 ax(4) = subplot (224);
 set (ax(4), 'tag', '4');
 plot (x, rand (3, 11));
 title ('x & y labels & ticklabels');
 xlabel xlabel;
 ylabel ylabel;

end

try
  if (~ exist ('subplot_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    subplot_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "subplot_03.png" ... ');
      tic ();
      print ('-dpng', 'subplot_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "subplot_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in subplot_03: %s\n', lasterr ());
  err_fid = fopen ('subplot_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function subplot_04 ()
    
 clf;
 x = 0:10;
 subplot (221);
  plot (x, rand (3, 11));
  ylim ([0, 1]);
  text (0.5, 0.5, '{x,y}labels & {x,y}ticklabels', ...
                  'horizontalalignment', 'center', ...
                  'units', 'normalized');
  xlabel xlabel;
  ylabel ylabel;
  title title;
 subplot (222);
  plot (x, rand (3, 11));
  axis ('labely');
  ylabel ylabel;
  text (0.5, 0.5, 'no xlabels, xticklabels', ...
                  'horizontalalignment', 'center', ...
                  'units', 'normalized');
 subplot (223);
  plot (x, rand (3, 11));
  axis ('labelx');
  text (0.5, 0.5, 'no ylabels, yticklabels', ...
                  'horizontalalignment', 'center', ...
                  'units', 'normalized');
  xlabel xlabel;
  title title;
 subplot (224);
  plot (x, rand (3, 11));
  axis ('nolabel', 'tic');
  text (0.5, 0.5, 'no {x,y}labels, {x,y}ticklabels', ...
                  'horizontalalignment', 'center', ...
                  'units', 'normalized');

end

try
  if (~ exist ('subplot_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    subplot_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "subplot_04.png" ... ');
      tic ();
      print ('-dpng', 'subplot_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "subplot_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in subplot_04: %s\n', lasterr ());
  err_fid = fopen ('subplot_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function zoom_01 ()
    
 clf;
 sombrero ();
 title ('zoom() demo #1');
 pause (1);
 %% zoom in by a factor of 2
 zoom (2);
 pause (1);
 %% return to original zoom level
 zoom out;
 pause (1);
 %% zoom in by a factor of 2
 zoom (2);
 pause (1);
 %% set this zoom level as the 'initial zoom level'
 %% and zoom in some more
 zoom reset;
 zoom (2);
 pause (1);
 %% return to zoom level set by last call to 'zoom reset'
 zoom out;

end

try
  if (~ exist ('zoom_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    zoom_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "zoom_01.png" ... ');
      tic ();
      print ('-dpng', 'zoom_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "zoom_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in zoom_01: %s\n', lasterr ());
  err_fid = fopen ('zoom_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

close all

function autumn_01 ()
    
 %% Show the 'autumn' colormap profile and as an image
 cmap = autumn (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('autumn_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    autumn_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "autumn_01.png" ... ');
      tic ();
      print ('-dpng', 'autumn_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "autumn_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in autumn_01: %s\n', lasterr ());
  err_fid = fopen ('autumn_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function bone_01 ()
    
 %% Show the 'bone' colormap profile and as an image
 cmap = bone (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('bone_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    bone_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "bone_01.png" ... ');
      tic ();
      print ('-dpng', 'bone_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "bone_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in bone_01: %s\n', lasterr ());
  err_fid = fopen ('bone_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function brighten_01 ()
    
 %% First figure uses default grayscale colormap
 clf;
 colormap (gray (64));
 image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64));
 axis ([1, 64, 0, 1], 'xy');
 set (gca, 'xtick', []);
 title ('default grayscale colormap');
 pos = get (gcf, 'position');
 pos(1) = pos(1) + pos(3) + 25;
 %% Second figure uses brightened grayscale colormap
 figure ('position', pos);
 colormap (gray (64));
 image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64));
 axis ([1, 64, 0, 1], 'xy');
 set (gca, 'xtick', []);
 brighten (0.5);
 title ('grayscale colormap brightened by 0.5');

end

try
  if (~ exist ('brighten_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    brighten_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "brighten_01.png" ... ');
      tic ();
      print ('-dpng', 'brighten_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "brighten_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in brighten_01: %s\n', lasterr ());
  err_fid = fopen ('brighten_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function cmpermute_01 ()
    
 [Y, newmap] = cmpermute ([1:4], hot (4), 4:-1:1)
 %% colormap will be arranged in reverse order (so will image)

end

try
  if (~ exist ('cmpermute_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    cmpermute_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "cmpermute_01.png" ... ');
      tic ();
      print ('-dpng', 'cmpermute_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "cmpermute_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in cmpermute_01: %s\n', lasterr ());
  err_fid = fopen ('cmpermute_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function cmunique_01 ()
    
 [Y, newmap] = cmunique ([1:4;5:8], [hot(4);hot(4)])
 %% Both rows are equal since map maps colors to the same value
 %% cmunique will give the same indices to both

end

try
  if (~ exist ('cmunique_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    cmunique_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "cmunique_01.png" ... ');
      tic ();
      print ('-dpng', 'cmunique_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "cmunique_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in cmunique_01: %s\n', lasterr ());
  err_fid = fopen ('cmunique_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function colorcube_01 ()
    
 %% Show the 'colorcube' colormap as an image
 image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64));
 axis ([1, 64, 0, 1], 'xy');
 set (gca, 'xtick', []);
 colormap (colorcube (64));

end

try
  if (~ exist ('colorcube_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    colorcube_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "colorcube_01.png" ... ');
      tic ();
      print ('-dpng', 'colorcube_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "colorcube_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in colorcube_01: %s\n', lasterr ());
  err_fid = fopen ('colorcube_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function contrast_01 ()
    
 clf;
 img = reshape (1:100, 10, 10);
 imagesc (img);
 colormap (gray (64));
 title ('Image with default 64 gray levels');
 pos = get (gcf, 'position');
 pos(1) = pos(1) + pos(3) + 25;
 figure ('position', pos);
 colormap (contrast (img, 10));
 imagesc (img);
 title ('Image with contrast enhanced');

end

try
  if (~ exist ('contrast_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    contrast_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "contrast_01.png" ... ');
      tic ();
      print ('-dpng', 'contrast_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "contrast_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in contrast_01: %s\n', lasterr ());
  err_fid = fopen ('contrast_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function cool_01 ()
    
 %% Show the 'cool' colormap profile and as an image
 cmap = cool (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('cool_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    cool_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "cool_01.png" ... ');
      tic ();
      print ('-dpng', 'cool_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "cool_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in cool_01: %s\n', lasterr ());
  err_fid = fopen ('cool_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function copper_01 ()
    
 %% Show the 'copper' colormap profile and as an image
 cmap = copper (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('copper_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    copper_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "copper_01.png" ... ');
      tic ();
      print ('-dpng', 'copper_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "copper_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in copper_01: %s\n', lasterr ());
  err_fid = fopen ('copper_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function cubehelix_01 ()
    
 %% Show the 'cubehelix' colormap profile and as an image
 cmap = cubehelix (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('cubehelix_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    cubehelix_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "cubehelix_01.png" ... ');
      tic ();
      print ('-dpng', 'cubehelix_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "cubehelix_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in cubehelix_01: %s\n', lasterr ());
  err_fid = fopen ('cubehelix_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function flag_01 ()
    
 %% Show the 'flag' colormap profile and as an image
 cmap = flag (12);  % 4 colors, therefore cycle 3 times
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('flag_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    flag_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "flag_01.png" ... ');
      tic ();
      print ('-dpng', 'flag_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "flag_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in flag_01: %s\n', lasterr ());
  err_fid = fopen ('flag_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function getframe_01 ()
    
 clf;
 contourf (rand (5));
 drawnow ();
 frame = getframe ();
 imshow (frame.cdata);

end

try
  if (~ exist ('getframe_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    getframe_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "getframe_01.png" ... ');
      tic ();
      print ('-dpng', 'getframe_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "getframe_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in getframe_01: %s\n', lasterr ());
  err_fid = fopen ('getframe_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function getframe_02 ()
    
 clf reset;
 contourf (rand (5));
 frame = getframe (gcf ());
 imshow (frame.cdata);
 set (gca, 'position', [0 0 1 1]);

end

try
  if (~ exist ('getframe_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    getframe_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "getframe_02.png" ... ');
      tic ();
      print ('-dpng', 'getframe_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "getframe_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in getframe_02: %s\n', lasterr ());
  err_fid = fopen ('getframe_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function getframe_03 ()
    
 clf;
 hax1 = subplot (2,1,1);
 contourf (rand (5));
 title ('Original');
 frame = getframe (hax1);
 hax2 = subplot (2,1,2);
 image (frame.cdata);
 title ('Frame');

end

try
  if (~ exist ('getframe_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    getframe_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "getframe_03.png" ... ');
      tic ();
      print ('-dpng', 'getframe_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "getframe_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in getframe_03: %s\n', lasterr ());
  err_fid = fopen ('getframe_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function getframe_04 ()
    
 clf;
 hax1 = subplot (2,1,1);
 contourf (rand (5));
 title ('Original');

 %% Get the coordinates of the lower-left hand corner in pixels
 set (hax1, 'units', 'pixels');
 pos = get (hax1, 'position');
 set (hax1, 'units', 'normalized');
 rect = [pos(1:2) pos(3:4)/2];

 frame = getframe (hax1, rect);
 hax2 = subplot (2,1,2);
 image (frame.cdata);
 title ('Lower left hand corner');

end

try
  if (~ exist ('getframe_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    getframe_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "getframe_04.png" ... ');
      tic ();
      print ('-dpng', 'getframe_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "getframe_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in getframe_04: %s\n', lasterr ());
  err_fid = fopen ('getframe_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function gray_01 ()
    
 %% Show the 'gray' colormap profile and as an image
 cmap = gray (16);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('gray_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    gray_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "gray_01.png" ... ');
      tic ();
      print ('-dpng', 'gray_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "gray_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in gray_01: %s\n', lasterr ());
  err_fid = fopen ('gray_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function hot_01 ()
    
 %% Show the 'hot' colormap profile and as an image
 cmap = hot (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('hot_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    hot_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "hot_01.png" ... ');
      tic ();
      print ('-dpng', 'hot_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "hot_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in hot_01: %s\n', lasterr ());
  err_fid = fopen ('hot_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function hsv_01 ()
    
 %% Show the 'hsv' colormap profile and as an image
 cmap = hsv (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('hsv_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    hsv_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "hsv_01.png" ... ');
      tic ();
      print ('-dpng', 'hsv_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "hsv_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in hsv_01: %s\n', lasterr ());
  err_fid = fopen ('hsv_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function image_01 ()
    
 clf;
 colormap (jet (21));
 img = 1 ./ hilb (11);
x = -5:5;
y = -5:5;
 subplot (2,2,1);
  h = image (x, y, img);
  ylabel ('limits = [-5.5, 5.5]');
  title ('image (x, y, img)');
 subplot (2,2,2);
  h = image (-x, y, img);
  title ('image (-x, y, img)');
 subplot (2,2,3);
  h = image (x, -y, img);
  title ('image (x, -y, img)');
  ylabel ('limits = [-5.5, 5.5]');
 subplot (2,2,4);
  h = image (-x, -y, img);
  title ('image (-x, -y, img)');

end

try
  if (~ exist ('image_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    image_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "image_01.png" ... ');
      tic ();
      print ('-dpng', 'image_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "image_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in image_01: %s\n', lasterr ());
  err_fid = fopen ('image_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imagesc_01 ()
    
 clf;
 colormap ('default');
 img = 1 ./ hilb (11);
x = -5:5;
y = -5:5;
 subplot (2,2,1);
  h = imagesc (x, y, img);
  ylabel ('limits = [-5.5, 5.5]');
  title ('imagesc (x, y, img)');
 subplot (2,2,2);
  h = imagesc (-x, y, img);
  title ('imagesc (-x, y, img)');
 subplot (2,2,3);
  h = imagesc (x, -y, img);
  title ('imagesc (x, -y, img)');
  ylabel ('limits = [-5.5, 5.5]');
 subplot (2,2,4);
  h = imagesc (-x, -y, img);
  title ('imagesc (-x, -y, img)');

end

try
  if (~ exist ('imagesc_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    imagesc_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imagesc_01.png" ... ');
      tic ();
      print ('-dpng', 'imagesc_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imagesc_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imagesc_01: %s\n', lasterr ());
  err_fid = fopen ('imagesc_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imagesc_02 ()
    
 clf;
 colormap ('default');
 g = 0.1:0.1:10;
 h = g'*g;
 imagesc (g, g, sin (h));
 hold on;
 imagesc (g, g+12, cos (h/2));
 axis ([0 10 0 22]);
 hold off;
 title ('two consecutive images w/hold()');

end

try
  if (~ exist ('imagesc_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    imagesc_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imagesc_02.png" ... ');
      tic ();
      print ('-dpng', 'imagesc_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imagesc_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imagesc_02: %s\n', lasterr ());
  err_fid = fopen ('imagesc_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imagesc_03 ()
    
 clf;
 colormap ('default');
 g = 0.1:0.1:10;
 h = g'*g;
 imagesc (g, g, sin (h));
 hold on;
 plot (g, 11.0 * ones (size (g)));
 imagesc (g, g+12, cos (h/2));
 axis ([0 10 0 22]);
 hold off;
 title ('image, line, image w/hold()');

end

try
  if (~ exist ('imagesc_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    imagesc_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imagesc_03.png" ... ');
      tic ();
      print ('-dpng', 'imagesc_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imagesc_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imagesc_03: %s\n', lasterr ());
  err_fid = fopen ('imagesc_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imagesc_04 ()
    
 clf;
 colormap ('default');
 g = 0.1:0.1:10;
 h = g'*g;
 plot (g, 10.5 * ones (size (g)));
 hold on;
 imagesc (g, g, sin (h));
 plot (g, 11.0 * ones (size (g)));
 imagesc (g, g+12, cos (h/2));
 plot (g, 11.5 * ones (size (g)));
 axis ([0 10 0 22]);
 hold off;
 title ('line, image, line, image, line w/hold()');

end

try
  if (~ exist ('imagesc_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    imagesc_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imagesc_04.png" ... ');
      tic ();
      print ('-dpng', 'imagesc_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imagesc_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imagesc_04: %s\n', lasterr ());
  err_fid = fopen ('imagesc_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imagesc_05 ()
      % bug %48879
 clf;
 img = reshape (1:100, 10, 10);
 imagesc (img);
 colormap (prism (10));
 title ('10 vertical color bars');

end

try
  if (~ exist ('imagesc_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    imagesc_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imagesc_05.png" ... ');
      tic ();
      print ('-dpng', 'imagesc_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imagesc_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imagesc_05: %s\n', lasterr ());
  err_fid = fopen ('imagesc_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imshow_01 ()
    
 clf;
 imshow ('default.img');

end

try
  if (~ exist ('imshow_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    imshow_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imshow_01.png" ... ');
      tic ();
      print ('-dpng', 'imshow_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imshow_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imshow_01: %s\n', lasterr ());
  err_fid = fopen ('imshow_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imshow_02 ()
    
 clf;
 imshow ('default.img');
 colormap (gca, autumn (64));

end

try
  if (~ exist ('imshow_02.png', 'file'))
    rand ('seed', 1);
    tic ();
    imshow_02 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imshow_02.png" ... ');
      tic ();
      print ('-dpng', 'imshow_02.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imshow_02.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imshow_02: %s\n', lasterr ());
  err_fid = fopen ('imshow_02.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imshow_03 ()
    
 clf;
 [I, M] = imread ('default.img');
 imshow (I, M);

end

try
  if (~ exist ('imshow_03.png', 'file'))
    rand ('seed', 1);
    tic ();
    imshow_03 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imshow_03.png" ... ');
      tic ();
      print ('-dpng', 'imshow_03.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imshow_03.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imshow_03: %s\n', lasterr ());
  err_fid = fopen ('imshow_03.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imshow_04 ()
    
 clf;
 [I, M] = imread ('default.img');
 [R, G, B] = ind2rgb (I, M);
 imshow (cat (3, R, G*0.5, B*0.8));

end

try
  if (~ exist ('imshow_04.png', 'file'))
    rand ('seed', 1);
    tic ();
    imshow_04 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imshow_04.png" ... ');
      tic ();
      print ('-dpng', 'imshow_04.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imshow_04.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imshow_04: %s\n', lasterr ());
  err_fid = fopen ('imshow_04.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imshow_05 ()
    
 clf;
 imshow (rand (100, 100));
 title ({'imshow with random 100x100 matrix', 'black and white'});

end

try
  if (~ exist ('imshow_05.png', 'file'))
    rand ('seed', 1);
    tic ();
    imshow_05 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imshow_05.png" ... ');
      tic ();
      print ('-dpng', 'imshow_05.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imshow_05.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imshow_05: %s\n', lasterr ());
  err_fid = fopen ('imshow_05.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imshow_06 ()
    
 clf;
 imshow (rand (100, 100));
 colormap (gca, jet (64));
 title ({'imshow with random 100x100 matrix', 'colormap() makes color image'});

end

try
  if (~ exist ('imshow_06.png', 'file'))
    rand ('seed', 1);
    tic ();
    imshow_06 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imshow_06.png" ... ');
      tic ();
      print ('-dpng', 'imshow_06.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imshow_06.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imshow_06: %s\n', lasterr ());
  err_fid = fopen ('imshow_06.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imshow_07 ()
    
 clf;
 imshow (rand (100, 100, 3));
 title ({'imshow with random 100x100x3 matrix', 'RGB color'});

end

try
  if (~ exist ('imshow_07.png', 'file'))
    rand ('seed', 1);
    tic ();
    imshow_07 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imshow_07.png" ... ');
      tic ();
      print ('-dpng', 'imshow_07.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imshow_07.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imshow_07: %s\n', lasterr ());
  err_fid = fopen ('imshow_07.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function imshow_08 ()
    
 clf;
 imshow (100*rand (100, 100, 3));
 title ({'imshow with random 100x100x3 matrix', 'RGB values > 1 are clipped'});

end

try
  if (~ exist ('imshow_08.png', 'file'))
    rand ('seed', 1);
    tic ();
    imshow_08 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "imshow_08.png" ... ');
      tic ();
      print ('-dpng', 'imshow_08.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "imshow_08.png" already exists.\n');
  end
catch
  fprintf ('ERROR in imshow_08: %s\n', lasterr ());
  err_fid = fopen ('imshow_08.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function jet_01 ()
    
 %% Show the 'jet' colormap profile and as an image
 cmap = jet (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('jet_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    jet_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "jet_01.png" ... ');
      tic ();
      print ('-dpng', 'jet_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "jet_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in jet_01: %s\n', lasterr ());
  err_fid = fopen ('jet_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function lines_01 ()
    
 %% Show the 'lines' colormap profile and as an image
 cmap = lines (21); % default has 7 colors, therefore cycle 3 times
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('lines_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    lines_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "lines_01.png" ... ');
      tic ();
      print ('-dpng', 'lines_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "lines_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in lines_01: %s\n', lasterr ());
  err_fid = fopen ('lines_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function ocean_01 ()
    
 %% Show the 'ocean' colormap profile and as an image
 cmap = ocean (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('ocean_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    ocean_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "ocean_01.png" ... ');
      tic ();
      print ('-dpng', 'ocean_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "ocean_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in ocean_01: %s\n', lasterr ());
  err_fid = fopen ('ocean_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function pink_01 ()
    
 %% Show the 'pink' colormap profile and as an image
 cmap = pink (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('pink_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    pink_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "pink_01.png" ... ');
      tic ();
      print ('-dpng', 'pink_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "pink_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in pink_01: %s\n', lasterr ());
  err_fid = fopen ('pink_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function prism_01 ()
    
 %% Show the 'prism' colormap profile and as an image
 cmap = prism (18); % 6 colors, therefore cycle 3 times
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('prism_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    prism_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "prism_01.png" ... ');
      tic ();
      print ('-dpng', 'prism_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "prism_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in prism_01: %s\n', lasterr ());
  err_fid = fopen ('prism_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function rainbow_01 ()
    
 %% Show the 'rainbow' colormap profile and as an image
 cmap = rainbow (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('rainbow_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    rainbow_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "rainbow_01.png" ... ');
      tic ();
      print ('-dpng', 'rainbow_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "rainbow_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in rainbow_01: %s\n', lasterr ());
  err_fid = fopen ('rainbow_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function rgbplot_01 ()
    
 clf;
 subplot (1, 2, 1);
  rgbplot (ocean, 'profile');
 subplot (1, 2, 2);
  rgbplot (ocean, 'composite');

end

try
  if (~ exist ('rgbplot_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    rgbplot_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "rgbplot_01.png" ... ');
      tic ();
      print ('-dpng', 'rgbplot_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "rgbplot_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in rgbplot_01: %s\n', lasterr ());
  err_fid = fopen ('rgbplot_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function spinmap_01 ()
    
 clf;
 colormap (rainbow (128));
 imagesc (1:8);
 axis off;
 title ('Rotate color bars to the right');
 spinmap (3, 1);

end

try
  if (~ exist ('spinmap_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    spinmap_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "spinmap_01.png" ... ');
      tic ();
      print ('-dpng', 'spinmap_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "spinmap_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in spinmap_01: %s\n', lasterr ());
  err_fid = fopen ('spinmap_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function spring_01 ()
    
 %% Show the 'spring' colormap profile and as an image
 cmap = spring (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('spring_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    spring_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "spring_01.png" ... ');
      tic ();
      print ('-dpng', 'spring_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "spring_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in spring_01: %s\n', lasterr ());
  err_fid = fopen ('spring_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function summer_01 ()
    
 %% Show the 'summer' colormap profile and as an image
 cmap = summer (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('summer_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    summer_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "summer_01.png" ... ');
      tic ();
      print ('-dpng', 'summer_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "summer_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in summer_01: %s\n', lasterr ());
  err_fid = fopen ('summer_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function viridis_01 ()
    
 %% Show the 'viridis' colormap profile and as an image
 cmap = viridis (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('viridis_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    viridis_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "viridis_01.png" ... ');
      tic ();
      print ('-dpng', 'viridis_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "viridis_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in viridis_01: %s\n', lasterr ());
  err_fid = fopen ('viridis_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function white_01 ()
    
 %% Show the 'white' colormap profile and as an image
 cmap = white (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('white_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    white_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "white_01.png" ... ');
      tic ();
      print ('-dpng', 'white_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "white_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in white_01: %s\n', lasterr ());
  err_fid = fopen ('white_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

function winter_01 ()
    
 %% Show the 'winter' colormap profile and as an image
 cmap = winter (256);
 subplot (2, 1, 1);
  rgbplot (cmap, 'composite');
 subplot (2, 1, 2);
  rgbplot (cmap);

end

try
  if (~ exist ('winter_01.png', 'file'))
    rand ('seed', 1);
    tic ();
    winter_01 ();
    t_plot = toc ();
    fig = (get (0, 'currentfigure'));
    if (~ isempty (fig))
      fprintf ('Printing "winter_01.png" ... ');
      tic ();
      print ('-dpng', 'winter_01.png');
      t_print = toc ();
      fprintf ('[%f %f] done\n',t_plot, t_print);
    end
    clf reset;
  else
    fprintf ('File "winter_01.png" already exists.\n');
  end
catch
  fprintf ('ERROR in winter_01: %s\n', lasterr ());
  err_fid = fopen ('winter_01.err', 'w');
  fprintf (err_fid, '%s', lasterr ());
  fclose (err_fid);
end

close all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Helper functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [x, y, z] = sombrero (n)                                            
                                                                             
  if (nargin == 0)                                                           
    n = 41;                                                                  
  end                                                                        
                                                                             
  [xx, yy] = meshgrid (linspace (-8, 8, n));                                 
  r = sqrt (xx.^2 + yy.^2) + eps;  % eps prevents div/0 errors               
  zz = sin (r) ./ r;                                                         
                                                                             
  if (nargout == 0)                                                          
    surf (xx, yy, zz);                                                       
  elseif (nargout == 1)                                                      
    x = zz;                                                                  
  else                                                                       
    x = xx;                                                                  
    y = yy;                                                                  
    z = zz;                                                                  
  end                                                                        
                                                                             
end                                                                          

function h = rgbplot (cmap, style)                                           
                                                                             
  if (nargin == 1)                                                           
    style = 'profile';                                                       
  end                                                                        
                                                                             
  idx = 1:size (cmap, 1);                                                    
  switch (lower (style))                                                     
    case 'profile'                                                           
      htmp = plot (idx, cmap(:,1), 'r', ...                                  
                   idx, cmap(:,2), 'g', ...                                  
                   idx, cmap(:,3), 'b');                                     
      set (gca (), 'ytick', 0:0.1:1);                                        
      set (gca (), 'xlim', [0 size(cmap,1)]);                                
    case 'composite'                                                         
      htmp = image (idx);                                                    
      set (gca, 'ytick', []);                                                
      colormap (cmap);                                                       
  end                                                                        
  xlabel ('color index');                                                    
                                                                             
  if (nargout > 0)                                                           
    h = htmp;                                                                
  end                                                                        
                                                                             
end                                                                          


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

diary off
end

