Removing unwanted lines from text file
古いコメントを表示
I am trying to remove all the NaN from column 7 of the attached text file and move them into a new text file.
I have written the code below:
% - Read original.
content = fileread( 'virgorm.txt' ) ;
% - Match and eliminate lines without pattern matching.
sepId = reshape( strfind( content, '|' ), 7, [] ) ;
match = content(sepId(7,:)+1) == 'NaN' ;
lines = strsplit( content, '\n' ) ;
lines(match) = [] ;
% - Export updated content.
fId = fopen( 'virgormwou.txt', 'w' ) ;
fprintf( fId, strjoin( lines, '\n' )) ;
fclose( fId ) ;
But, it doesn't seem to be working. I suspect it is because of line:
match = content(sepId(7,:)+1) == 'NaN' ;
The error I get is:
Error using reshape Product of known dimensions, 7, not divisible into total number of elements, 6492.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!