Issue with data format when using textscan()

3 visualizaciones (últimos 30 días)
Chamath Vithanawasam
Chamath Vithanawasam el 23 de Jul. de 2018
Comentada: Chamath Vithanawasam el 24 de Jul. de 2018
I am trying to collect data from a .txt file and add it into a matrix in Matlab for plotting purposes, but there seems to be an error when collecting the data. It seems to be happening with the time record.
I am using the following code snippet.
fileID = fullfile('SI010118.txt')
C = textscan(fileID, '%{dd.MM.yyyy}D %{HH:MM:SS}T %f %f %f %f %f %f %f %d %d %d %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %{HH:MM:SS}T %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f')
The error shows as follows.
Error using textscan
Unable to parse the format character vector at position 16 ==> %{HH:MM:SS}T %f %f %f %f %f %f %f %d %d %d %f %f %f %f %f %f %f %f %f %f
%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f
%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %{HH:MM:SS}T %f %f %f %f %f %f %f
%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f
%f %f %f
Date formats must be of the form %T or %{...}T.
The .txt file I am using is attached.
  1 comentario
Paolo
Paolo el 23 de Jul. de 2018
Editada: Paolo el 23 de Jul. de 2018
That second datetime format should be:
%{HH:mm:SS}D
D is for datetime and T is for duration.
Also if you are trying to read starting from the line which starts with:
01.01.2018 00:00:44;29.59;30.16;29.59; etc...
You should use HeaderFiles name value pair when using textscan function.

Iniciar sesión para comentar.

Respuesta aceptada

Jeremy Hughes
Jeremy Hughes el 23 de Jul. de 2018
The format should be all lower case for duration.
%{hh:mm:ss}T
However, the data appears to be delimited as semicolon. You'd have more luck with readtable:
opts = detectImportOptions('D:\SI010118.txt')
opts = setvartype(opts,1,'datetime')
opts = setvaropts(opts,1,'InputFormat','dd.MM.uuuu HH:mm:ss')
readtable('D:\SI010118.txt',opts)

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by