필터 지우기
필터 지우기

Inputting Date Time data and presenting as a graph

조회 수: 3 (최근 30일)
Sophia
Sophia 2021년 12월 7일
댓글: Sophia 2021년 12월 13일
A = importdata('08_underwater.txt')
A = readtimetable('08_underwater.txt')
A.Properties.VariableNames{1} = 'Light';
A.Time.Format='M/dd/yyyy HH:mm'
plot(A.Time,A.Light)
^ with this the x axis appears totally wrong as I am plotting data for only 01/12/21 - 03/12/21
Light is correctly displayed on the y axis
I would like to show light changes over time over the three days
I am wondering if the x axis requires more formatting?

답변 (1개)

Chunru
Chunru 2021년 12월 7일
A = readtimetable('08_underwater.csv')
Warning: The DATETIME data was created using format 'MM/dd/uuuu HH:mm:ss' but also matched 'dd/MM/uuuu HH:mm:ss'.
To avoid ambiguity, supply a datetime format using SETVAROPTS, e.g.
opts = setvaropts(opts,varname,'InputFormat','MM/dd/uuuu HH:mm:ss');
A = 675×1 timetable
Datetime Light ___________________ _____ 01/12/2021 09:35:00 100.6 01/12/2021 09:40:00 111.4 01/12/2021 09:45:00 106.2 01/12/2021 09:50:00 86.2 01/12/2021 09:55:00 87.3 01/12/2021 10:00:00 88.8 01/12/2021 10:05:00 100.5 01/12/2021 10:10:00 110.5 01/12/2021 10:15:00 124 01/12/2021 10:20:00 137.3 01/12/2021 10:25:00 143.4 01/12/2021 10:30:00 150.6 01/12/2021 10:35:00 159.7 01/12/2021 10:40:00 152.7 01/12/2021 10:45:00 134.4 01/12/2021 10:50:00 106.8
A.Properties.VariableNames{1} = 'Light';
plot(A.Datetime,A.Light)
  댓글 수: 29
Chunru
Chunru 2021년 12월 13일
Use the same data and code here.
opts = detectImportOptions('08_underwater.csv');
opts = setvaropts(opts, 'Datetime', 'InputFormat', 'dd/MM/uuuu HH:mm');
% type 08_underwater.csv
A = readtable('08_underwater.csv', opts);
plot(A.Datetime,A.Light)
Sophia
Sophia 2021년 12월 13일
Perfect, thanks so much for your help! Really appreciate it

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by