Hello .I have the following question :I am reading a text file using the usual
textread(filename,'%s%s%s%f%f%d','delimiter',',').Sometimes though the file is corrupted and instead of a number as expected ,in one of the fields ,there is an INF .
How do I change the program so I can simply avoid these lines completely ?
Many thanks,
Constantin

3 comentarios

madhan ravi
madhan ravi el 23 de En. de 2019
Editada: madhan ravi el 23 de En. de 2019
upload your file and which version of matlab are you using?
Constantin milea
Constantin milea el 23 de En. de 2019
Cannot ,is a proprietary one but a line looks like this basically :
EQ235464,Mining,Active,SPY,23.4,34,5,INF,230
madhan ravi
madhan ravi el 23 de En. de 2019
try reading the file using readtable()

Iniciar sesión para comentar.

 Respuesta aceptada

Stephan
Stephan el 23 de En. de 2019
Editada: Stephan el 23 de En. de 2019

1 voto

Hi,
use readtable like suggested by Madhan. If it is always in column 8 of your data like your example given use logical indexing:
filename = 'filename.txt';
result = readtable(filename)
result(result.Var8==Inf,:) = []
using this example as file, where line 5 and 9 are corrupt:
EQ235464,Mining,Active,SPY,23.4,34,5,1,230
EQ235464,Mining,Active,SPY,23.4,34,5,2,230
EQ235464,Mining,Active,SPY,23.4,34,5,3,230
EQ235464,Mining,Active,SPY,23.4,34,5,4,230
EQ235464,Mining,Active,SPY,23.4,34,5,INF,230
EQ235464,Mining,Active,SPY,23.4,34,5,6,230
EQ235464,Mining,Active,SPY,23.4,34,5,7,230
EQ235464,Mining,Active,SPY,23.4,34,5,8,230
EQ235464,Mining,Active,SPY,23.4,34,5,INF,230
EQ235464,Mining,Active,SPY,23.4,34,5,10,230
results in:
result =
10×9 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9
__________ ________ ________ _____ ____ ____ ____ ____ ____
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 1 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 2 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 3 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 4 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 Inf 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 6 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 7 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 8 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 Inf 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 10 230
result =
8×9 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9
__________ ________ ________ _____ ____ ____ ____ ____ ____
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 1 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 2 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 3 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 4 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 6 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 7 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 8 230
'EQ235464' 'Mining' 'Active' 'SPY' 23.4 34 5 10 230
Best regards
Stephan

1 comentario

Constantin milea
Constantin milea el 23 de En. de 2019
Many thanks for both answers ,yes is working great

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre App Building en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 23 de En. de 2019

Comentada:

el 23 de En. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by