Removing unwanted lines from text file
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!