フィルターのクリア

Reading txt file by character number defined columns

1 回表示 (過去 30 日間)
Nikolay Rodionov
Nikolay Rodionov 2013 年 5 月 9 日
Hi guys, I am trying to read in data from a GRO file where the data is organized into columns that are defined by character numbers. For example, on any given row, characters 1-5 will have one type of data, 6-8 will have a different piece of data, and so on.
What's the best function to use read this file into an array?
Thanks! Nikolay

回答 (1 件)

per isakson
per isakson 2013 年 5 月 10 日
The gro file format is described at Gromacs. There is no best way to read gro-files with Matlab - I think. One way is:
fid = fopen( 'cssm.txt' );
rw1 = fgetl( fid );
rw2 = fgetl( fid );
N = str2double( rw2 );
ca1 = textscan ...
( fid, '%5d%-5s%5s%5d%8.3f%8.3f%8.3f%8.4f%8.4f%8.4f', N, 'Delimiter', '' );
ca2 = textscan( fid, '%f%f%f' );
fclose( fid );
where cssm.txt contains
MD of 2 waters, t= 0.0
6
1WATER OW1 1 0.126 1.624 1.679 0.1227 -0.0580 0.0434
1WATER HW2 2 0.190 1.661 1.747 0.8085 0.3191 -0.7791
1WATER HW3 3 0.177 1.568 1.613 -0.9045 -2.6469 1.3180
2WATER OW1 4 1.275 0.053 0.622 0.2519 0.3140 -0.1734
2WATER HW2 5 1.337 0.002 0.680 -1.0641 -1.1349 0.0257
2WATER HW3 6 1.326 0.120 0.568 1.9427 -0.8216 -0.0244
1.82060 1.82060 1.82060

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by