How to call a .txt file containing dates in format "01-JAN-2019" and time against three other independent variables to MATLAB?

1 visualizzazione (ultimi 30 giorni)
Ive attached the file i'd like to call and then use to plot further into multiple plots, however when I use "fileread('data.txt')", I get all the data in a 1xn matrix that I cannot use to plot.
  3 Commenti
Akshay Saini
Akshay Saini il 15 Apr 2021
@RikHi thank you for the reply, how exactly do I convert the characters to a different data type? And how do I determine the correct data type I need for my plot to work? Thank you.
Rik
Rik il 15 Apr 2021
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 16 Apr 2021
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/584765/data.txt';
t = readtable(filename, 'Format', '%s%s%s%s%C%C%C', 'readvariablenames', false);
t.Time = datetime(strcat(t{:,1},'-',t{:,2},'-',t{:,3},{' '},t{:,4}));
t.Properties.VariableNames(5:7) = {'Status1', 'Status2', 'Status3'};
plot(t.Time, t.Status1)
Not the greatest of plots, but the data cannot be treated as numeric as it contains entries such as InVld and NoData and <Samp and down and pwrfail and ca1 and it is difficult to know how to plot those.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by