Sibbs Gambling
Sibbs Gambling

Reputation: 20405

Plot against time of format "hh:mm:ss" in MATLAB?

I have a bunch of time-indexed data, that I have to plot with MATLAB.

The current format of the time is as follows

23:55:42,-147928.686833054
23:55:43,-147928.404621219
23:55:44,-147928.219419702
23:55:45,-147928.395802099
23:55:46,-147928.492812417
23:55:47,-147928.413440339
23:55:48,-147928.386982979

I simply wish to plot the second column, the values, against the first column, the time.

I can of course take the first time point as 0, and next as 1, ..., and so on. However, I wish to stick with the original timing.

How may I deal with this type of time handily?

Upvotes: 0

Views: 2076

Answers (2)

Ben Voigt
Ben Voigt

Reputation: 283941

Convert your time values using datenum. Create an X-Y plot in the usual way. And ask for time-formatted labels with

datetick('x', 13)

For example:

plot(datenum(a(:,1)), a(:,2));
datetick('x', 13)

Upvotes: 2

Adiel
Adiel

Reputation: 3071

Try the property "XTickLabel" after plotting.

You can use it with a cell of strings of your data:

plot(second-column-values)
Times={'23:55:42','23:55:43',...}     
set(gca,'XTickLabel',Times)

Upvotes: 0

Related Questions