Effacer les filtres
Effacer les filtres

Read specific column from txt file

2 vues (au cours des 30 derniers jours)
Aleksandra
Aleksandra le 20 Juil 2012
Hi, I would like to read specific column from txt file (values - 3230,3190,3220 and so on). So how can I do it?
Thanks.
Here is the txt file looks like:
1 7/19/2012 11:46:38 AM L 0 254 3230 3.6 0.18 97
1 7/19/2012 11:46:52 AM L 0 249 3190 3.6 0.18 97
1 7/19/2012 11:47:05 AM L 0 252 3220 3.6 0.18 97
2 7/19/2012 11:49:05 AM L 0 390 4180 4.2 0.18 95
2 7/19/2012 11:53:09 AM L 0 399 4240 4.5 0.18 91

Réponse acceptée

bym
bym le 21 Juil 2012
fid = fopen('test.txt')
n = textscan(fid,'%*d %*s %*s %*s %*s %*f %*f %f %*f %*f %*f','delimiter',' ')
n{:}
ans =
3230
3190
3220
4180
4240
  3 commentaires
Walter Roberson
Walter Roberson le 22 Juil 2012
Modifié(e) : Walter Roberson le 22 Juil 2012
It would be safer to remove the embedded blanks in the format string. Also, since all those fields are being thrown away, it does not make sense to do the extra processing of deciding whether they are proper numeric form. Suggested format:
[repmat('%*s',1,6), '%f', repmat('%*s',1,3)]
Also, is your delimiter blanks or tabs? It looks like blanks, but I cannot be sure. If it is blanks, you can also drop the explicit 'delimiter' parameter/value pair.
Aleksandra
Aleksandra le 23 Juil 2012
Yeah, I didn't use 'delimiter' since thre is no delimiter there. Thanks a lot!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by