필터 지우기
필터 지우기

how to create date variable or column

조회 수: 6 (최근 30일)
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2019년 5월 10일
댓글: Star Strider 2019년 5월 10일
Dear All, I have numeric matrix of 3 columns and 100 rows, the 1st column is A and represents day number from 1 to 30, the 2nd column is B and represents month number from 1 to 12, the 3rd one is the year, how can I please create 4th column for the date in the format mm/dd/year? by combining the 3 columns. And then add this column with this format to the matrix as a 4th column. thank you
  댓글 수: 4
James Tursa
James Tursa 2019년 5월 10일
Readers are going to be reluctant to download an Excel spreadsheet. Can you provide what you have on the MATLAB side? Do you need help in loading the spreadsheet into MATLAB?
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2019년 5월 10일
What do you mean by spreadsheet? I have the data in a matrix in the workspace

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

채택된 답변

Star Strider
Star Strider 2019년 5월 10일
Your data have a two-digit year. Assuming ‘10’ means ‘2010’, try this:
D = xlsread('data.xlsx');
Col4 = datetime(fliplr(D)+[2000 0 0], 'Format','MM/dd/yyyy');
producing:
Col4 =
22×1 datetime array
01/01/2010
01/01/2010
01/01/2010
01/01/2010
. . .
Using a table:
Tbl = table(D(:,1),D(:,2),D(:,3),Col4, 'VariableNames',{'Day','Month','Year','All'})
produces:
Tbl =
22×4 table
Day Month Year All
___ _____ ____ __________
1 1 10 01/01/2010
1 1 10 01/01/2010
1 1 10 01/01/2010
1 1 10 01/01/2010
. . .
  댓글 수: 2
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2019년 5월 10일
This is very very helpful thank you very much
Star Strider
Star Strider 2019년 5월 10일
As always, my pleasure.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by