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

1 view (last 30 days)
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 Comments
Akshay Saini
Akshay Saini on 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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 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.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!