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 commentaires

madhan ravi
madhan ravi le 23 Jan 2019
Modifié(e) : madhan ravi le 23 Jan 2019
upload your file and which version of matlab are you using?
Constantin milea
Constantin milea le 23 Jan 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 le 23 Jan 2019
try reading the file using readtable()

Connectez-vous pour commenter.

 Réponse acceptée

Stephan
Stephan le 23 Jan 2019
Modifié(e) : Stephan le 23 Jan 2019

1 vote

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 commentaire

Constantin milea
Constantin milea le 23 Jan 2019
Many thanks for both answers ,yes is working great

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur App Building dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by