Convert the date string into date vector and expending existing matrix
Ältere Kommentare anzeigen
Hi,
I want to convert the date string into date vector and store it back into the matrix by expending the existing matrix
this the data source:
21/10/2012 16:00:00 0 81.34
21/10/2012 17:00:00 0 87.52
here is the new matrix that I failed to work it out:
yy mm dd hh mm ss
2012 10 21 16 0 0 0 81.34
2012 10 21 17 0 0 0 87.52
here is my code
d1a = rain_txt(i); % date string formation like 21/10/2012 16:00:00
formatIn = 'dd/mm/yyyy HH:MM:SS';
mat2= vec2mat(datevec(d1a,formatIn),6);
thank you
4 Kommentare
Oleg Komarov
am 10 Jun. 2014
What does 0 81.34 stand for? You need to exclude the last two columns.
Noor Mohd Safar
am 10 Jun. 2014
Geoff Hayes
am 10 Jun. 2014
Bearbeitet: Geoff Hayes
am 10 Jun. 2014
@Zuraidin - you mentioned in your question that d1a is a date string formation like 21/10/2012 16:00:00'. So does that mean it does not include columns 2 and 3 from the Excel spreadsheet containing data like 0 and 81.34? If I run the following
d1a = '21/10/2012 16:00:00';
formatIn = 'dd/mm/yyyy HH:MM:SS';
datevec(d1a,formatIn)
then the answer is
ans =
2012 10 21 16 0 0
which seems to be almost what you want. The above is a 1x6 vector, so it is not clear to me why you call the vec2mat function with this input and the 6. And if you are expecting the 0 and 81.34 to appear on the end, then you have to extract this data (from wherever it is) and append it to the end of the above result.
When you say that the code is still not working, what do you mean by that?
Noor Mohd Safar
am 10 Jun. 2014
Bearbeitet: Noor Mohd Safar
am 10 Jun. 2014
Antworten (2)
Joseph Cheng
am 10 Jun. 2014
A quick easy way to do this is
text=['21/10/2012 16:00:00 0 81.34';
'21/10/2012 17:00:00 0 87.52']
temp(find(temp=='/'))=' ';
temp(find(temp==':'))=' ';
for i =1:size(text,1)
A(i,:) = strread(temp(i,:))
end
which will give you
A =
21 10 2012 16 0 0 0 81.34
21 10 2012 17 0 0 0 87.52
1 Kommentar
Noor Mohd Safar
am 10 Jun. 2014
Noor Mohd Safar
am 15 Jan. 2016
Kategorien
Mehr zu Time Series Objects finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!