views:

44

answers:

2

Hello,

I have imported date&time data from a text file, in which it was stored as a string, to Matlab. I can convert string to numeric data and back, by using datenum and datestr commands.

My problem is with creating figures. I can easily plot data against numeric date&time values, but as it is stored as a number, it is not very useful. On the other hand, I found it impossible to plot data against strings. Is there a way that data would be plotted against numeric date&time value, but presented in a friendly way as a string?

Best regards,

+1  A: 

Have a look at datetick. Or you may prefer rotate tick label. More on tweaking tick labels is provided by stackoverflow post.

zellus
Hamilcar
Check the documentation for 'ResizeFcn'. Using *set(gcf, 'ResizeFcn', @resizeFunctionHandle)*' you may assign a function (handle) with the resize event. In this case *resizeFunctionHandle* is executed on every figure resize.
zellus
A: 

I'm not sure if this is you are asking for:

date_numeric = 1:5;
date_string={'date_1' 'date_2' 'date_3' 'date_4' 'date_5'};
y = rand(size(date_numeric));
plot(date_numeric, y, 'b')
set(gca, 'XTick',1:5, 'XTickLabel',date_string)

alt text

Harpreet