Fixed-width data import with textread()
Show older comments
Hi guys,
Thanks for your help in advance. I'm having issues importing some data using textread(). I am trying to use it to import a fixed-width txt dataset, but the function is blending some data columns when there is no whitespace between string and numerical datatypes.
Specifically, I am trying to import a data extract from a gromacs .gro file. You can find information about the data structure here: http://manual.gromacs.org/online/gro.html
My code:
[resnum resname atomname atomnr x y z a b c] ...
= textread('conf-mod.gro','%5d%5s%-5s%5d%8.3f%8.3f%8.3f%8.4f%8.4f%8.4f');
It works for data lines like:
1ALA CA 3 56.249 52.119 83.467 0.0000 0.0000 0.0000
But it blends 'atomname' and 'atomnr' data into the 'atomname' column for lines like this:
14195ASP OD119731 55.954 54.890 95.494 0.0000 0.0000 0.0000
Note: 'atomname' should equal OD here, and 'resname' comes out fine strangely enough. I don't understand why this is happening because I've clearly outlined the fixed width format of the dataset. I've tried converting %-5s to %-5c, but it did not help.
Any suggestions?
Accepted Answer
More Answers (0)
Categories
Find more on Convert Image Type 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!