Modify text in a column
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dear all, I want to modify just the first column of a file, removing the letters and keeping the numbers. The columns contain string like d200n-h. How it is possible?
Thanks,
Marco
0 comentarios
Respuestas (1)
Walter Roberson
el 26 de Jun. de 2019
Editada: Walter Roberson
el 26 de Jun. de 2019
Assuming comma delimited:
S = fileread('YourFile.txt');
newS = regexprep(S, '^\D*(\d+)[^,]+(,.*$)', '$1$2', 'lineanchors', 'dotexceptnewline');
fid = fopen('YourNewFile.txt');
fwrite(fid, newS);
fclose(fid)
This should work even if there is "" around the string, but it will remove the "" if present.
2 comentarios
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!