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开发者_StackOverflow社区&time value, but presented in a friendly way as a string?
Best regards,
Have a look at datetick. Or you may prefer rotate tick label. More on tweaking tick labels is provided by stackoverflow post.
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)
精彩评论