Inputting Date Time data and presenting as a graph
Ältere Kommentare anzeigen
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?
Antworten (1)
A = readtimetable('08_underwater.csv')
A.Properties.VariableNames{1} = 'Light';
plot(A.Datetime,A.Light)
29 Kommentare
Sophia
am 7 Dez. 2021
Chunru
am 7 Dez. 2021
Use "readtimetable" as shown above.
Chunru
am 7 Dez. 2021
Or change Time to 'Datetime' (with quotes).
Sophia
am 7 Dez. 2021
Chunru
am 7 Dez. 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
am 7 Dez. 2021
Chunru
am 7 Dez. 2021
Post your complete code.
Sophia
am 7 Dez. 2021
Chunru
am 7 Dez. 2021
Your code please. (.m file not .mat file)
Sophia
am 7 Dez. 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
am 7 Dez. 2021
Chunru
am 7 Dez. 2021
You should have pointed it out earlier. Corrected above.
Sophia
am 7 Dez. 2021
Sophia
am 12 Dez. 2021
Chunru
am 12 Dez. 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
am 12 Dez. 2021
Chunru
am 12 Dez. 2021
What is your matlab version?
Sophia
am 12 Dez. 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
am 12 Dez. 2021
Chunru
am 12 Dez. 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
am 12 Dez. 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
am 12 Dez. 2021
Chunru
am 13 Dez. 2021
Post your data.
Sophia
am 13 Dez. 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
am 13 Dez. 2021
Kategorien
Mehr zu Dates and Time finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


