how to plot time from string

8 Ansichten (letzte 30 Tage)
Sergio Mendoza
Sergio Mendoza am 22 Okt. 2019
Beantwortet: Star Strider am 22 Okt. 2019
I have the following time vector:
T =
'21:01'
'21:02'
'21:03'
'21:04'
and when i try to convert it into a variable I can plot:
Time2plot = datetime(T, 'inputformat','HH:mm');
it automatically assigns today and the date for it. I don't want to have a date associated to it.
Any ideas?

Akzeptierte Antwort

Star Strider
Star Strider am 22 Okt. 2019
Use the 'Format' name-value pair:
T = ['21:01'
'21:02'
'21:03'
'21:04'];
Time2plot = datetime(T, 'inputformat','HH:mm', 'Format','HH:mm')
produces:
Time2plot =
4×1 datetime array
21:01
21:02
21:03
21:04
For the plot, use the xtickformat function:
figure
plot(Time2plot, rand(4,1))
grid
xtickformat('HH:mm')
However, it still has the date associated with it below the x-axis.
The only way I can think of to get around that is:
dn = datenum(Time2plot);
figure
plot(dn, rand(4,1))
grid
datetick('x', 'hh:mm', 'keepticks')
Experiment to get the result you want.

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by