フィルターのクリア

Splitting a string of numbers into two seperate strings.

3 ビュー (過去 30 日間)
Dillon Trimmell
Dillon Trimmell 2022 年 1 月 31 日
コメント済み: Benjamin Thompson 2022 年 1 月 31 日
I have a (n,1) array of Dates and Times, I want to seperate the Date from the Time so I can easily identify the Day and the Time on other functions.
an example of this data is.. Data(1,1)='01/01 01:00:00', Data(2,1)= '01/01 02:00:00' and so on.
I would like it so that I can split this data into something of the sort:
For i=1:length(Data)
Time(i)=strsplit(Data(i),' ');
Date(i)=strsplit(Data(i),' ');
end
Where the Time is just the time portion of the string and the Date Array is just the Date of the string.
Ive tried using strsplit but am not very familiar with the way the function works. Any help on this would be aprecciated.
Thank you.
  1 件のコメント
Stephen23
Stephen23 2022 年 1 月 31 日
編集済み: Stephen23 2022 年 1 月 31 日
"...so I can easily identify the Day and the Time on other functions."
Using DATETIME objects would be much better than fiddling around with text:

サインインしてコメントする。

回答 (1 件)

Benjamin Thompson
Benjamin Thompson 2022 年 1 月 31 日
The datetime function is very flexible:
datetime('01/01 01:00:00', 'InputFormat', 'MM/yy HH:mm:SS')
ans =
datetime
01-Jan-2001 01:00:00
It can convert an array of strings also. Then you can work with the objects as datetime objects.
  3 件のコメント
Stephen23
Stephen23 2022 年 1 月 31 日
編集済み: Stephen23 2022 年 1 月 31 日
"...I want to be able to plot hourly rate of energy usgae and I would like to have an array of just the time."
Using DATETIME would likely make that easier than fiddling around with text.
Benjamin Thompson
Benjamin Thompson 2022 年 1 月 31 日
Remember to accept answers you like!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeString についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by