how to read complicated text file
Afficher commentaires plus anciens
Hello,
How to read the following "complicated" text file via textscan?
see attached file.dat:
name | multiplicity | pos | rot | excore
------------------------------------------------
a | 2 | 2 3 | 1 | 1
b | 1 | 1 2 3 | 6 | 1
c | 2 | 1 | 6 | 0
...
------------------------------------------------
The number of rows is uknown. The number of integers at column "pos" is variable.
Réponse acceptée
Plus de réponses (2)
ES
le 19 Sep 2013
use textscan with delimiter '|'
FileObj=fopen(FileName);
CellData=textscan(FileObj, ...
'%s %s %s %s %s %s %s %s %s', 'delimiter', '|');
1 commentaire
Michal Kvasnicka
le 19 Sep 2013
Azzi Abdelmalek
le 19 Sep 2013
Modifié(e) : Azzi Abdelmalek
le 19 Sep 2013
fid = fopen('file.txt');
line1 = fgetl(fid);
res={line1};
while ischar(line1)
line1 = fgetl(fid);
res{end+1} =line1
end
fclose(fid);
res(end)=[]
1 commentaire
Michal Kvasnicka
le 19 Sep 2013
Modifié(e) : Michal Kvasnicka
le 19 Sep 2013
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!