Import and plot file with day and time information

4 visualizaciones (últimos 30 días)
Ancalagon8
Ancalagon8 el 7 de Nov. de 2018
Editada: Ancalagon8 el 6 de En. de 2025
I have a file and i cannot manage to plot my data correctly. I can plot values as datapoints but i need also the time.. Anyone who can help?
  1 comentario
Guillaume
Guillaume el 7 de Nov. de 2018
An actual file instead of a picture of it would be a lot more useful for us to test.
i cannot manage to plot my data correctly. To tell what you did wrong we need to know what you did.

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 7 de Nov. de 2018
I'm not sure what you're doing wrong since you haven't shown us what you're doing. The following may be what you're after:
t = readtable('data3.csv');
t.datetime = t.(1) + t.(2); %merge date and time into one variable
plot(t.datetime, t{:, 3:5});
  7 comentarios
Guillaume
Guillaume el 8 de Nov. de 2018
Well, then it is not meant to be the same time! Yes, some samples are at the second, but the fraction of second would be different. Unfortunately, that information is not embedded in your text file. The best would be to fix whatever created these text files so that it writes the sub-second information.
There are many ways you could fix this depending on how robust you want it to be. If we assume that all the samples in one text file are all continuous and acquire at a rate of 125 Hz then a simple way to solve the problem is to cumulatively add 1/125 second to the timing of the 1st sample (thus completely ignoring the embedded timing of the remaining samples). If that is acceptable, then:
t.datetime = datetime(strcat(t{1, 1}, {' '}, t{1, 2}) + ... %timing of 1st sample
seconds(1/125) * (0:height(t)-1)'; %cumulatively add 1/125 second to timing of each sample
Guillaume
Guillaume el 8 de Nov. de 2018
Well, most likely the error you actually received was Invalid Expression as I forgot a closing bracket. You must have added the bracket in the wrong place.
t.datetime = datetime(strcat(t{1, 1}, {' '}, t{1, 2})) + ... %timing of 1st sample
seconds(1/125) * (0:height(t)-1)'; %cumulatively add 1/125 second to timing of each sample
Or since you don't really care about the actual acquisition time of the samples, you could simply ignore the time information from the text file and do:
plot(seconds(1/125) * (0:height(t)-1), t{:, 3:5})

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by