Effacer les filtres
Effacer les filtres

Inputting Date Time data and presenting as a graph

3 vues (au cours des 30 derniers jours)
Sophia
Sophia le 7 Déc 2021
Commenté : Sophia le 13 Déc 2021
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?

Réponses (1)

Chunru
Chunru le 7 Déc 2021
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 commentaires
Chunru
Chunru le 13 Déc 2021
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 le 13 Déc 2021
Perfect, thanks so much for your help! Really appreciate it

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by