필터 지우기
필터 지우기

How to create a table with a timedate

조회 수: 8 (최근 30일)
J.FENG
J.FENG 2023년 4월 6일
댓글: Star Strider 2023년 4월 6일
I am trying to create table like with a column which shows the date from 2022-6-1 to 2022-9-26, and the row shows the time at 21h, 24h,3h,6h,9h,12h,15h,18h like the excel I draw below.
Here is my code, but it doesn't works fine
dates = datetime('2022-06-01'):days(1):datetime('2022-09-26');
times = {'21h', '24h', '3h', '6h', '9h', '12h', '15h', '18h'};
table_data = zeros(length(dates), length(times));
T = array2table(table_data, 'RowNames', times, 'ColumnNames', string(dates));

채택된 답변

Star Strider
Star Strider 2023년 4월 6일
편집: Star Strider 2023년 4월 6일
Try this —
dates = datetime('2022-06-01'):days(1):datetime('2022-09-26');
times = {'21h', '24h', '3h', '6h', '9h', '12h', '15h', '18h'};
varTypes = {'double' 'double' 'double' 'double' 'double' 'double' 'double' 'double'}; % Change This As Necessary
T = table('Size',[numel(dates),numel(times)], 'VariableTypes',varTypes, 'VariableNames',times, 'RowNames',cellstr(dates.'))
T = 118×8 table
21h 24h 3h 6h 9h 12h 15h 18h ___ ___ __ __ __ ___ ___ ___ 01-Jun-2022 0 0 0 0 0 0 0 0 02-Jun-2022 0 0 0 0 0 0 0 0 03-Jun-2022 0 0 0 0 0 0 0 0 04-Jun-2022 0 0 0 0 0 0 0 0 05-Jun-2022 0 0 0 0 0 0 0 0 06-Jun-2022 0 0 0 0 0 0 0 0 07-Jun-2022 0 0 0 0 0 0 0 0 08-Jun-2022 0 0 0 0 0 0 0 0 09-Jun-2022 0 0 0 0 0 0 0 0 10-Jun-2022 0 0 0 0 0 0 0 0 11-Jun-2022 0 0 0 0 0 0 0 0 12-Jun-2022 0 0 0 0 0 0 0 0 13-Jun-2022 0 0 0 0 0 0 0 0 14-Jun-2022 0 0 0 0 0 0 0 0 15-Jun-2022 0 0 0 0 0 0 0 0 16-Jun-2022 0 0 0 0 0 0 0 0
.
  댓글 수: 4
J.FENG
J.FENG 2023년 4월 6일
it works!! thanks !!!
Star Strider
Star Strider 2023년 4월 6일
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