Inputting Date Time data and presenting as a graph
Mostra commenti meno recenti
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?
Risposte (1)
A = readtimetable('08_underwater.csv')
A.Properties.VariableNames{1} = 'Light';
plot(A.Datetime,A.Light)
29 Commenti
Sophia
il 7 Dic 2021
Chunru
il 7 Dic 2021
Use "readtimetable" as shown above.
Chunru
il 7 Dic 2021
Or change Time to 'Datetime' (with quotes).
Sophia
il 7 Dic 2021
Chunru
il 7 Dic 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
il 7 Dic 2021
Chunru
il 7 Dic 2021
Post your complete code.
Sophia
il 7 Dic 2021
Chunru
il 7 Dic 2021
Your code please. (.m file not .mat file)
Sophia
il 7 Dic 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
il 7 Dic 2021
Chunru
il 7 Dic 2021
You should have pointed it out earlier. Corrected above.
Sophia
il 7 Dic 2021
Sophia
il 12 Dic 2021
Chunru
il 12 Dic 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
il 12 Dic 2021
Chunru
il 12 Dic 2021
What is your matlab version?
Sophia
il 12 Dic 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
il 12 Dic 2021
Chunru
il 12 Dic 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
il 12 Dic 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
il 12 Dic 2021
Chunru
il 13 Dic 2021
Post your data.
Sophia
il 13 Dic 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
il 13 Dic 2021
Categorie
Scopri di più su Dates and Time in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


