MATLAB Answers

How do I import a txt file with the white spaces

2 views (last 30 days)
Roshen Jegajeevan
Roshen Jegajeevan on 2 Mar 2021
Edited: Meg Noah on 2 Apr 2021
I have to edit a .22 file and change one of the columns. It is pretty much a text file with a matrix. It is parsed with a comma as a delimiter. However I want to retrieve the values in between the commas while maintaining the white space between the commas. So when I export the matrix after I've changed it, it will be the exact same with one changed column.
  3 Comments
Walter Roberson
Walter Roberson on 2 Mar 2021
A = readlines('fort.22');
Now A{6} would be the 6th line, and you could use text processing on it in any way you like, including extracting from fixed character positions, calculating something, and replacing those fixed character positions using a careful format.
However... when I look at your code, it looks more likely that you want to change column 6, rather than row 6. It does not make a lot of difference though.

Sign in to comment.

Answers (1)

Meg Noah
Meg Noah on 2 Apr 2021
Edited: Walter Roberson on 3 Apr 2021
This seems to work if you don't mind working with a table
readtable('file22.txt','whitespace','','delimiter',',')

Tags

Community Treasure Hunt

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

Start Hunting!