Convert the date string into date vector and expending existing matrix
古いコメントを表示
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 件のコメント
Oleg Komarov
2014 年 6 月 10 日
What does 0 81.34 stand for? You need to exclude the last two columns.
Noor Mohd Safar
2014 年 6 月 10 日
Geoff Hayes
2014 年 6 月 10 日
編集済み: Geoff Hayes
2014 年 6 月 10 日
@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
2014 年 6 月 10 日
編集済み: Noor Mohd Safar
2014 年 6 月 10 日
回答 (2 件)
Joseph Cheng
2014 年 6 月 10 日
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
Noor Mohd Safar
2016 年 1 月 15 日
カテゴリ
ヘルプ センター および File Exchange で Time Series Objects についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!