Code covered by the BSD License  

Highlights from
Date Odometer class

image thumbnail

Date Odometer class

by

 

12 Apr 2011 (Updated )

Add an odometer-like object to a plot to show the progression of time.

create_odometer_images(destination_directory)
function create_odometer_images(destination_directory)
% Creates odometer digit images.
%
% create_odometer_images(destination_directory)
%
% Input:
%    destination_directory  Where the files are to be placed.

% Kevin J. Delaney, BMT Scientific Marine Services,
% April 13 2011

if ~exist('destination_directory', 'var')
    help(mfilename);
    return
end

if isempty(destination_directory) || ~ischar(destination_directory)
    errordlg('Input "destination_directory" is empty or non-char.', ...
        mfilename);
    return
end

make_sure_directory_exists(destination_directory);

figure_handle = figure;
h = uicontrol('Units', 'pixels', ...
              'BackgroundColor', 'w', ...
              'FontSize', 24, ...
              'FontWeight', 'b', ...
              'Parent', figure_handle, ...
              'Position', [450, 45, 30, 42], ...
              'String', '0', ...
              'Style', 'text');

%   Warm up. Otherwise the first image is bad.
F = getframe(figure_handle, get(h, 'Position'));
X = frame2im(F); %#ok<NASGU>

for k = 0:9
    set(h, 'String', num2str(k));
    F = getframe(figure_handle, get(h, 'Position'));
    X = frame2im(F);
    imwrite(X, fullfile(destination_directory, [num2str(k), '.png']));
end
           
month_cell = {'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', ...
              'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'};
set(h, 'Position', [400, 45, 70, 42]);
           
for k = 1:length(month_cell)    
    set(h, 'String', month_cell{k});
    F = getframe(figure_handle, get(h, 'Position'));
    X = frame2im(F);
    imwrite(X, fullfile(destination_directory, [month_cell{k}, '.png']));
end    
   
symbol_cell = {' ', ':', ',', '-', '/'};
symbol_name_cell = {'blank', 'colon', 'comma', 'dash', 'slash'};
set(h, 'FontSize', 18, ...
       'FontWeight', 'b', ...
       'Position', [450, 45, 30, 42]);
          
for k = 1:length(symbol_cell)    
    set(h, 'String', symbol_cell{k});
    F = getframe(figure_handle, get(h, 'Position'));
    X = frame2im(F);
    imwrite(X, fullfile(destination_directory, [symbol_name_cell{k}, '.png']));
end    

delete(figure_handle);

Contact us