I gathered some data in this format
17:51:10 927.00
17:51:15 950.00
17:51:21 827.00
17:51:27 999.00
17:51:33 1088.00
17:51:38 1094.00
17:51:44 1109.00
as you can see first part is time and second is the data.
I extracted data using this code
fid = fopen('.\test.txt','r');
cac = textscan(fid, '%f%f%f%f','Delimiter', ':');
data=cac{:,4};
HH=cac{:,1};
MM=cac{:,2};
SS=cac{:,3};
And tried to plot them using a timeseries function
ts1 = timeseries(data,(HH:MM:SS));
To my dissapointment it doesn't plot and the ts1 variable seems to be invalid.
Is there some other way of ploting time data ? Or am I using the timeseries function wrong ?

2 comentarios

Slawomir Kania
Slawomir Kania el 21 de Mzo. de 2018
Editada: Slawomir Kania el 21 de Mzo. de 2018
BTW, all the data seem to produce correct horizontal arrays data, HH - hours, MM - minutes, SS - seconds
Von Duesenberg
Von Duesenberg el 21 de Mzo. de 2018
What if you simplify your workflow, load your data with the readtable function, convert your table to a timetable with the table2timetable function, and plot the first column against the second?

Iniciar sesión para comentar.

 Respuesta aceptada

dpb
dpb el 21 de Mzo. de 2018

0 votos

timeseries doesn't plot anything; all it does is create a timeseries object. Per the documentation, the data for the time vector is either an array of doubles or date strings; you passed neither format but a cell array.
Try
c=textscan(fid,'%s%f'); % read time as cell, data as float
ts=timeseries(c{2},c{1}); % build a timeseries object therefrom
fid=fclose(fid);
plot(ts)
I've not used the timeseries object enough to know how to clean up the display into something more user-friendly, but that gets the base object created for you to play with further.
Frankly, what little I've tried to 'spearmint with it, the timeseries just seems to be in the way more than help as compared to just using datetime or the venerable datenum
Mayhaps someone with more specific experience can elucidate further than what does the documentation on how to convert the above to more pleasing units in seconds and all...

Más respuestas (0)

Categorías

Productos

Preguntada:

el 21 de Mzo. de 2018

Respondida:

dpb
el 21 de Mzo. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by