How do I plot time (hh:mm:ss.000) vs samples as imported from a .csv file?

10 visualizaciones (últimos 30 días)
Please see the attached .csv file. I am trying to read time (hh:mm:ss.000) and plot it vs Sample 1 or Sample 2. 000 are milliseconds. The issue I have is that when I read time with the import tool, it gets read as a constant variable. How do I read time and plot it with the file formatting vs my samples? If the import tool can't read time in this format, how do I import time with the specified formatting as a variable to plot against my samples? I am using Matlab version R2016a.
Thank you for your time.

Respuestas (1)

Benjamin Kraus
Benjamin Kraus el 30 de Jul. de 2018
If you upgrade to R2018a, this process is a little more straightforward, but this code will work in R2016a.
Step 1: Import your data and update the variable names:
t = readtable('Test.csv','ReadVariableNames',true);
t.Properties.VariableNames{1} = 'Time';
Step 2: Convert the first column to duration. I cheat a little and use datetime to do the conversions. Note that this step is done automatically in R2018a, so you can skip it. In addition, in R2018a, you can do the conversion by calling duration directly, instead of using datetime.
t.Time= datetime(t.Time,'InputFormat','HH:mm:ss.SSS')-datetime('today');
t.Time.Format = 'hh:mm:ss.SSS';
Step 3: Plot
plot(t.Time, [t.Sample1 t.Sample2],'.-');
  2 comentarios
Jorge Zambrano
Jorge Zambrano el 2 de Ag. de 2018
This method worked beautifully. Thank you Benjamin.
Venkatapathi
Venkatapathi el 12 de En. de 2021
To understand this code, what concepts should i learn from MATLAB?

Iniciar sesión para comentar.

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by