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.

date_odometer_demo
function date_odometer_demo
% Demonstrates the use of the date_odometer class.

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

%
%   Use of date_odometer to time-stamp a plot.
%
figure_handle = figure;
axes_handle = axes('Parent', figure_handle, ...
                   'Position', [0.13, 0.15, 0.775, 0.75]);
pcolor(axes_handle, 1:100, 1:50, randn(50, 100));

for m = 1:10
    disp('.');
    pause(0.2);
end

disp('Let''s say you have a time-varying plot and want to show the date.');
disp('Add a date_odometer object, initialized with a starting date.');
disp('Example:');
disp('"h = date_odometer(figure_handle, datenum(2010, 12, 28, 00, 00, 00), position_vector);"');

for m = 1:2
    disp('.');
    pause(0.2);
end

h = date_odometer(figure_handle, datenum(2010, 12, 28, 00, 00, 00), [0.7, 0.05, 0.2, 0.05]);

input('Press Return to continue.');

for m = 1:10
    disp('.');
    pause(0.2);
end

disp('Invoke the "increment" method to roll the counter forward.');

for m = 1:2
    disp('.');
    pause(0.2);
end

%   Watch the odometer increment.
for k = 1:6
    pcolor(axes_handle, 1:100, 1:50, randn(50, 100));
    disp('"h.increment"');
    h.increment;
    pause(0.5);
end

input('Press Return to continue.');

for m = 1:10
    disp('.');
    pause(0.2);
end

disp('Invoke "increment" method with argument = (-1) to roll the counter backward.');

for m = 1:2
    disp('.');
    pause(0.2);
end

%   You can also run it backwards.
for k = 1:6
    pcolor(axes_handle, 1:100, 1:50, randn(50, 100));
    disp('"h.increment(-1)"');
    h.increment(-1);
    pause(0.5);
end
%
%   If making a "movie" (see help for "movie.m"), you can order a partial
%   increment, capture a frame, then partially increment again. That way,
%   when you play back the movie, you can see the odometer rolling.
%
input('Press Return to continue.');

for m = 1:10
    disp('.');
    pause(0.2);
end

disp('Invoke "increment" method with fractional argument (like 0.25) to roll the counter forward in steps.');
disp('This can be useful using "getframe" to record a moving image.');
drawnow;

for m = 1:2
    disp('.');
    pause(0.2);
end

frame_index = 0;

for k = 1:6
    pcolor(axes_handle, 1:100, 1:50, randn(50, 100));
    
    for n = 1:4
        disp('"h.increment(0.25)"');
        h.increment(0.25);
        frame_index = frame_index + 1;
        F(frame_index) = getframe(axes_handle);
    end
end
%
%   Some basic style choices are available.
%
delete(h);

input('Press Return to continue.');

for m = 1:10
    disp('.');
    pause(0.2);
end

disp('Initialize the date_odometer object using styles from "datestr" function.');
disp('"h = date_odometer(figure_handle, datenum(2010, 12, 28, 00, 00, 00), ...');
disp('                   position_vector, ''dd-mm-yyyy'');"');

for m = 1:2
    disp('.');
    pause(0.2);
end

h = date_odometer(figure_handle, datenum(2010, 12, 28, 00, 00, 00), [0.7, 0.05, 0.2, 0.05], 'dd/mm/yyyy');

%   Watch the odometer increment.
for k = 1:6
    pcolor(axes_handle, 1:100, 1:50, randn(50, 100));
    disp('"h.increment"');
    h.increment;
    pause(0.5);
end

input('That''s it! Press Return to continue.');
delete(figure_handle);

Contact us