RemekGdansk
RemekGdansk

Reputation: 73

How to present date as a string on matlab figure

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,

Upvotes: 2

Views: 1588

Answers (2)

user238469
user238469

Reputation:

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

Upvotes: 0

zellus
zellus

Reputation: 9592

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

Upvotes: 1

Related Questions