Convert minute date (stock data) to matlab from .csv

Dear all,
I've fairly new to MATLAB. Used it in a course Numerical Mathematics but we didn't have to import any data but only using it for calculations.
Well, now I have a vector with the following timedate structure: 26.01.2017 17:45:00.000,
I want this converted to a numerical vector so that I can plot the data and use it in a table or matrix with the rest of the variables (Open, Close, Volume).
I've read and tried to apply datenum and datestr but it didn't led to a succes.
I also have a problem with decimals when I import data and plot these.
I thank you in advance

 채택된 답변

Peter Perkins
Peter Perkins 2017년 6월 26일
If you are using a recent version of MATLAB, R2014b or later, it's likely you will be much happier using datetimes, rather than converting to a numeric value such as a serial date number. And if you are using R2016b or later, take a look at timetables.
To answer your specific question:
>> datetime('26.01.2017 17:45:00.000','Format','dd.MM.yyyy HH:mm:ss.SSS')
ans =
datetime
26.01.2017 17:45:00.000

댓글 수: 2

This worked and I thank you kindly for it. Just another question though: any idea how I can store the datetime variable with other numeric variables into a timetable?
Is this preferable?
Cheers!
In a timetable, you'd use the times to label each row, as the "row times". A timtable, like a table, allows you to put different data types in one rectangular array, with homogeneity enforced vertically (so not like a completely unconstrained cell array). The thing that's special about a timetable is that each row is labelled with a timestamp, either a datetime or a duration.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

markusha
markusha 2017년 6월 25일

0 개 추천

datenum('26.01.2017 17:45:00.000','dd.mm.yyyy HH:MM:SS.FFF') works for me.
Peter Perkins
Peter Perkins 2017년 6월 26일
Try this:
>> d = datetime(2017,06,12,13,31,60*sort(rand(10000,1)),'Format','dd-MM-yyyy HH:mm:ss.SSS');
>> x = randn(size(d));
>> plot(d(100:200),x(100:200))
Actually, there may bnot even be a compelling reason to plot a subset of the data, the plot lets you zoom in and the tick labels adjust their format automatically.

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

질문:

2017년 6월 25일

댓글:

2017년 6월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by