Inputting Date Time data and presenting as a graph
Mostrar comentarios más antiguos
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?
Respuestas (1)
A = readtimetable('08_underwater.csv')
A.Properties.VariableNames{1} = 'Light';
plot(A.Datetime,A.Light)
29 comentarios
Sophia
el 7 de Dic. de 2021
Chunru
el 7 de Dic. de 2021
Use "readtimetable" as shown above.
Chunru
el 7 de Dic. de 2021
Or change Time to 'Datetime' (with quotes).
Sophia
el 7 de Dic. de 2021
Chunru
el 7 de Dic. de 2021
You need to initialize opts before setvaropts:
opts = detectImportOptions('08_underwater.csv');
Have you used a different data file from what you uploaded?
Sophia
el 7 de Dic. de 2021
Chunru
el 7 de Dic. de 2021
Post your complete code.
Sophia
el 7 de Dic. de 2021
Chunru
el 7 de Dic. de 2021
Your code please. (.m file not .mat file)
Sophia
el 7 de Dic. de 2021
% You just need one of the two "read" to read the data
%
% The following returns a cell array. [Not recommended as you
% need to convert the format]
% A = importdata('08_underwater.csv')
% The following read in data as table.
opts = detectImportOptions('08_underwater.csv');
opts = setvaropts(opts, 'Datetime', 'InputFormat', 'dd/MM/uuuu HH:mm:ss');
type 08_underwater.csv
A = readtable('08_underwater.csv', opts)
% You don't need the following as the default above works well.
%
% opts = detectImportOptions('08_underwater.csv');
% opts = setvaropts(opts,'Datetime','InputFormat','M/dd/yyyy HH:mm');
plot(A.Datetime,A.Light)
Sophia
el 7 de Dic. de 2021
Chunru
el 7 de Dic. de 2021
You should have pointed it out earlier. Corrected above.
Sophia
el 7 de Dic. de 2021
Sophia
el 12 de Dic. de 2021
Chunru
el 12 de Dic. de 2021
All the code and data are in the post. The code is run on line. I have nothing else to share. Show how you run the code what is the error.
Sophia
el 12 de Dic. de 2021
Chunru
el 12 de Dic. de 2021
What is your matlab version?
Sophia
el 12 de Dic. de 2021
Run the following and show the output and error message
clear all
opts = detectImportOptions('08_underwater.csv')
opts = setvaropts(opts, 'Datetime', 'InputFormat', 'dd/MM/uuuu HH:mm:ss')
A = readtable('08_underwater.csv', opts)
plot(A.Datetime,A.Light)
Sophia
el 12 de Dic. de 2021
Chunru
el 12 de Dic. de 2021
Try the following:
A = readtable('08_underwater.csv', 'DatetimeType', 'text')
A.Datetime = datetime(A.Datetime, 'InputFormat', 'dd/MM/yyyy HH:mm:ss')
plot(A.Datetime,A.Light)
Sophia
el 12 de Dic. de 2021
You are using a different data file from what you posted. The datetime format uses '-' instead of '/'. Change that and try again.
datetime('3-12-2021 17:45', 'InputFormat', 'dd-MM-yyyy HH:mm:ss')
Sophia
el 12 de Dic. de 2021
Chunru
el 13 de Dic. de 2021
Post your data.
Sophia
el 13 de Dic. de 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
el 13 de Dic. de 2021
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


