how to plot datetime against number
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
rohail khan
el 10 de Abr. de 2018
Respondida: Peter Perkins
el 11 de Abr. de 2018
hi, I imported some data from excel file.I have two columns.One is dates and other is stocks. 'dates' column is of the form 'datetime' and 'stocks' is of the form 'double'. I just want to plot(dates,stocks) but it wont work. How can I plot dates with stocks or how to convert the dates to numeric?
0 comentarios
Respuesta aceptada
KSSV
el 10 de Abr. de 2018
You can plot class of datetime and double in MATLAB. Read the excel file using xlsread. Convert the columns of dates into class datetime using datetime.
t = datetime(2014,6,28) + calweeks(0:9);
y = rand(1,10);
plot(t,y);
Read about datetime.
2 comentarios
Más respuestas (1)
Peter Perkins
el 11 de Abr. de 2018
rohail, you don't need to convert anything if your data are already datetimes, which seems to be what you are indicating. Ideally, in recent releases of MATLAB and assuming your spreadsheet is properly formatted, all you need is
t = readtable('myfile.xlsx');
plot(t.Dates,t.Stocks)
readtable may end up returning you text for the dates if the spreadsheet is not formatted with date cells, in that case just convert to datetime as KSSV suggests.
0 comentarios
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!