How to concatenate table columns into one columns

1 view (last 30 days)
I have a Matlab table with three columns: Year, Month, Day. I want to make it into one column that represents the date in a format 'MM/dd/yyyy'. How can I do that? I tried quite a while to no avail, but I believe someone may know it immediately. Thanks.
The Table T has 3 columns (Year, Month, Day) and 10 rows.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 7 Aug 2015
Edited: Andrei Bobrov on 7 Aug 2015
T = [randi([2014 2016],10,1),randi([1 12],10,1),randi([1 28],10,1)];
out = datestr(datenum(T),'mm/dd/yyyy');
  2 Comments
JFz
JFz on 7 Aug 2015
Wow. It works! Exactly what I wanted to have! Thank you so much!
JFz
JFz on 7 Aug 2015
Curious, how does Matlab know which column is for Year, whichis for month? In the code, you didn't specify which column goes where?

Sign in to comment.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!