필터 지우기
필터 지우기

Matlab Report Generation Table format datetime string

조회 수: 4 (최근 30일)
Robert Miesen
Robert Miesen 2019년 6월 18일
답변: Eric 2019년 6월 19일
I want to put tables in a report. The table contains a colum of type datetime. Matlab fails to display the datetime and furthermore messes up the the colum headers. Bonus question: How can I remove the quotation marks from the string in the table?
Thanks
Code:
import mlreportgen.report.*
import mlreportgen.dom.*
R = Report('test', 'pdf');
open(R);
timeCol = datetime('now');
intCol = 1;
strCol = "abc";
testtable = table(timeCol, intCol, strCol);
MT = MATLABTable(testtable);
add(R, MT);
close(R)
Output:
timeCol intCol
1 "abc"

채택된 답변

Eric
Eric 2019년 6월 19일
To display the time, convert the datetime variable to a string. You can do this by calling the STRING function.
The double quotes are there because thats the display output of the MATLAB table shows. To remove the double quotes, use a CATEGORICAL array. See below code snippet.
import mlreportgen.report.*
import mlreportgen.dom.*
R = Report('test', 'pdf');
open(R);
timeCol = categorical(string(datetime('now')));
intCol = 1;
strCol = categorical("abc");
testtable = table(timeCol, intCol, strCol);
MT = MATLABTable(testtable);
add(R, MT);
close(R)

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by