how to read complicated text file
Show older comments
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.
Accepted Answer
More Answers (2)
ES
on 19 Sep 2013
use textscan with delimiter '|'
FileObj=fopen(FileName);
CellData=textscan(FileObj, ...
'%s %s %s %s %s %s %s %s %s', 'delimiter', '|');
1 Comment
Michal Kvasnicka
on 19 Sep 2013
Azzi Abdelmalek
on 19 Sep 2013
Edited: Azzi Abdelmalek
on 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 Comment
Michal Kvasnicka
on 19 Sep 2013
Edited: Michal Kvasnicka
on 19 Sep 2013
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!