Convert a table column of mixed data type to one data type

조회 수: 1 (최근 30일)
JFz
JFz 2016년 6월 16일
답변: Kirby Fears 2016년 6월 16일
Hi,
I have a table column that has both integers and strings. The integers are for dates. I would like to convert the integers to dates and then dates to strings.
How to do that?
Thanks in advance!
Jennifer
  댓글 수: 1
James Tursa
James Tursa 2016년 6월 16일
Please post a small example, showing exactly what you have in the column and what the desired output would be. Specifically, what is the integer value and how is it related to a date?

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

답변 (1개)

Kirby Fears
Kirby Fears 2016년 6월 16일
Jennifer,
Here's an example using a cell mixed type cell array "Var1" in table "t". You should be able to solve your problem with a similar approach.
t = cell2table({'date1',736495,'date2',736496,'date3',736497}');
ix = cellfun(@isnumeric,t.Var1);
t.Var1(ix) = cellfun(@(x)datestr(x,'yyyymmdd'),t.Var1(ix),'UniformOutput',false);

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by