Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Change numerical data points to dates

1 visualizzazione (ultimi 30 giorni)
David Shoen
David Shoen il 14 Ago 2020
Chiuso: MATLAB Answer Bot il 20 Ago 2021
Hi,
I have a data set that returns dates in my command window, which is what I want. The dates in the return window look as follows:
02-May-0120 00:00:00
02-Jun-0120 00:00:00
02-Jul-0120 00:00:00
02-Aug-0120 00:00:00
When I try to plot these dates on my x-axis, it lists them as numerical ticks. Please see attached. How do I get the graph to display my x axis data the same as it is returned in the command window?
Thanks,
David

Risposte (1)

Star Strider
Star Strider il 14 Ago 2020
Neither MATLAB nor I understand ‘0120’ in what otherwise appears to be the year field in the date vector.
Try this:
datstr = {'02-May-0120 00:00:00'
'02-Jun-0120 00:00:00'
'02-Jul-0120 00:00:00'
'02-Aug-0120 00:00:00'};
Dates = datetime(datstr, 'InputFormat','dd-MMM-01yy HH:mm:ss');
Data = rand(size(Dates));
figure
plot(Dates, Data)
grid
.

Prodotti


Release

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by