Delete a printed char in txt file?

Hi I have printed (138,139,140,141,142,143, };) in a text file and I'd like to remove the last ',' (the one after the '143') from the set. I tried \b does not work. How can I remove only one printed char?

Answers (1)

Guillaume
Guillaume on 15 Oct 2015
Edited: Guillaume on 15 Oct 2015
You can't, matlab does not have the facility of shortening a file. The best you can do is read the file, truncate the string, and rewrite it into a new file (with the same name if you want).
However, the best solution would be to not write that extra comma in the first place. How are you building your string? Note that strjoin can create a similar string without the extra comma:
v = 138:143;
strjoin(arrayfun(@num2str, v, 'UniformOutput', false), ',')

Categories

Tags

Asked:

on 15 Oct 2015

Edited:

on 15 Oct 2015

Community Treasure Hunt

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

Start Hunting!