Combine date and time

조회 수: 40 (최근 30일)
Amra Rajuli
Amra Rajuli 2021년 6월 1일
댓글: Amra Rajuli 2021년 6월 4일
I have 5 coloumn data consist year, month, date, hour and elevation data. I want to merge the data into two coloumn so it become:
coloumn1(datetime) coloumn 2
YYYY-MM-DD HH:mm:ss Elevation Data
I have tried some examples from matlab forum, but it not work. I used 2016b matlab version. Can anyone help me? Thank you.

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 6월 1일
The best way to combine data types (datetime and numeric) is to use a table. There are several possible approaches. Here is one.
  1. Load the table
  2. Use datetime to create Date from first 3 columns. Add hours(column 4) to it to complete datetime
  3. Create variable for elevation data
  4. Use table to combine Date and Elev
  5. Format the date
data = readmatrix("tidal data.txt");
Date = datetime(data(:,1:3)) + hours(data(:,4));
Elev = data(:,5);
T = table(Date,Elev);
T.Date.Format = 'yyyy-MM-DD HH:mm:ss'
T = 69445×2 table
Date Elev ____________________ ____ 2008-10-300 02:00:00 1772 2008-10-300 03:00:00 1712 2008-10-300 04:00:00 1650 2008-10-300 05:00:00 1637 2008-10-300 06:00:00 1715 2008-10-300 07:00:00 1761 2008-10-300 08:00:00 1907 2008-10-300 09:00:00 2069 2008-10-300 10:00:00 2129 2008-10-300 11:00:00 2150 2008-10-300 12:00:00 2096 2008-10-300 13:00:00 2046 2008-10-300 14:00:00 1963 2008-10-300 15:00:00 1842 2008-10-300 16:00:00 1765 2008-10-300 17:00:00 1745
  댓글 수: 1
Amra Rajuli
Amra Rajuli 2021년 6월 4일
Thank you very much. It is very helpful

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interface-Based Instrument Communication에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by