MATLAB axis relabeling
June 12, 2007 7:55 AM
Subscribe
Customizing MATLAB axes: Transform unixtime into date labels?
MATLAB gurus:
My figure's X axis currently consists of unix timestamps. I would like it to be labeled as YYYY/MM instead, and I'd like MATLAB to continue to work its magic as far as redrawing the axis prettily when the window is resized.
I found
this library to convert unixtimes to year/month and
this tutorial on customizing axes, but I still need some more help. (I can convert the times just fine, it's the axis stuff I don't understand.)
posted by dmd to computers & internet (5 comments total)
MATLAB axes have things called properties. One of these properties is called XTickLabel, and as you might suspect, it is what stores the labels for the ticks along the X axis. You set properties in MATLAB by doing
set(h,propname,val), wherehis the handle of the object whose properties you are trying to change,propnameis the name of the property, andvalis it's new value.What you want to do is set the XTickLabel property to your new array of converted timestamps. Suppose you have the converted timestamps stored in
x. You then doset(h,'XTickLabel',x), and you're done.Something you need to remember is that because you are using a YYYY/MM format, you have a non-numeric character in each tick label. This means that x needs to be either a character array or a cell array of strings. So your tick label array should look like one of these two:
x = ['2007/01'; '2007/02']x ={'2007/01' '2007/02'}The advantage of the latter is that the strings don't all need to be the same length.
posted by epugachev at 10:12 AM on June 12, 2007