File Exchange

image thumbnail

Zoom Adaptive Date Ticks

version 1.1.0.1 (1.6 KB) by

Make date ticks adapt to zooming

3 Downloads

Updated

View License

Editor's Note: This was a File Exchange Pick of the Week

Note that although this piece of code still works with R2014b, the same effect can be achieved by simply using the new datetime data type as first input to plot when running R2014b or newer versions.
%
% zoomAdaptiveDateTicks('on')
% Turns on the automatic adaptation of date ticks
% to user zooming for the current figure window
%
% zoomAdaptiveDateTicks('off')
% Turns off the automatic adaptation of date ticks
% to user zooming for the current figure window
%
% zoomAdaptiveDateTicks('demo')
% Opens a demo figure window to play with

Comments and Ratings (11)

I have a question about this script if anyone can answer that would be great.

First of all, this is a great script. However, I have a special problem. My time series is many days long (e.g. Feb 1 to Mar 15). And sometimes I need to zoom in on very specific times (e.g. 10:57 on Mar 2). However, when zooming, the date format switches from the date format I specified (yyyy-mm-dd HH:MM:SS; dateformat = 31) to simply HH:MM or to mm/yy.

Is there a way to force the function to maintain the dateformat which I specified?

Any help is appreciated.

Rafal Czarny

Diego

Diego (view profile)

lflorhid

Very, very useful.. thank you very much

Useful script! For multiple axes with linked time axis, I have modified the code to:
function adaptiveDateTicks(figureHandle,eventObjectHandle)
% Resetting x axis to automatic tick mark generation
ax=findall(figureHandle,'type','axes');
arrayfun(@(x) set(x,'XTickMode','auto'),ax)
% using automaticallly generate date ticks
arrayfun(@(x) datetick(x,'x','keeplimits'),ax)

Ryan Moffet

Thank you so much for this! I have struggled with 'manual mode' and updating date vectors for ages, this is such a simple and elegant solution.

Richard Stephens

This is just what I've been looking for!
Thanks.

Jeremy Almeter

This function is very useful. It is short, simple, and makes the graphs easier to read.

Les Beckham

This is nice and should prove useful.

The 'demo' feature uses the 'today' function which, apparently, only ships with the Financial toolbox. If you replace the line
dates = today - linspace(1169,0,15000)';
with
dates = floor(now) - linspace(1169,0,15000)';

it will work without the 'today' function.

Erik Stalberg

Thanks Andreas! This tool is very useful and the code is very well written.
Erik Stalberg

Updates

1.1.0.1

Updated license

1.1

Note for the new R2014b release.

MATLAB Release
MATLAB 7.4 (R2007a)
Acknowledgements

Inspired: cbdate

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today