How to convert time into matlab system?

1 view (last 30 days)
Hello everyone,
I have two columns A,B the first one ,A,contains a date (Year, Month and Day) while B contains hours and minutes. I want to create a third column C where I merge both columns. Initially, A and B were double so I used the next code to tranforme them to Matlab date system:
A = sp500_onemin(:,1)
d = datenum(num2str(A),'yyyymmdd')
date = datestr(d,20)
My first problem is when I tried to transform column B (composed by hours and minutes) and I used the nextc command, Matlab always gives me the same number in "time":
B = sp500_onemin(:,2)
t= num2str(B)
time= datenum(t,'HHMM')
Can someone please tell me where is my mistake?
After fixing this, how can I merge column A and B to have a new column compose by date and time?
Thanks a lot for your help!

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 23 Apr 2016
A={'2000/02/15' '12:30';'2015/03/16' '18:55'}
b=arrayfun(@(x) strjoin(A(x,:)),(1:size(A,1))','un',0)
out=[A b]

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!