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!