How can I get MATLAB to plot a date on the x-axis?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a dataset with column1 = date and column2 = data. The problem is that my date is in yyyymmdd format. How can I get MATLAB to plot the date correctly in the x-axis?
Thank you in advance! :)
2 Kommentare
Akzeptierte Antwort
dpb
am 21 Okt. 2013
First convert the text string date format to Matlab serial dates --
doc datenum
Then plot with that value as the x-axis value and format the dates as desired via
doc datetick
dn=datenum(data(:,1),'yyyymmdd');
plot(dn,data(:,2))
datetick('x','keepticks','keeplimits')
Salt to suit...
2 Kommentare
dpb
am 28 Jan. 2020
This answer is now out of date...use the new(ish) datetime class instead of datenum
Weitere Antworten (2)
Dainty Daisy Calgas
am 3 Dez. 2017
Hello, how could I plot a quarterly data with column1, written as Q1:1991 up to Q4:2016, then my column2 is my data., please I really need help, it was in the excel.
1 Kommentar
dpb
am 3 Dez. 2017
Better form would be to create a new question, but it is at least related so I'll consider it here as "close enough"... :)
Problem first is we need to know how the date data are actually stored and imported. Since the date of the original Q, TMW has introduced the datetime class/object and improved graphics routines to be datetime aware so things are different now than then...
Siehe auch
Kategorien
Mehr zu Calendar finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!