Partitioning data out of .txt files

I have a lot of old data scanned from hand writen notes. It was scanned in to a .txt file, the result being one long string of words and numbers. See data sample attached "archers_fieldnotes_scan".
The data consist of a location (or the shorthand note of it), a number, its result, then the next location, number, its result....repeat.
I need to break this information down into a usable matrix, consisting of 1 column vector fot the location, 1 column vector for the numeric value, and a thrid column vector of the result.
All I have been able to do with it so far is read the .txt file in as one long string.
txt=readlines("archer_fieldnotes_scan.txt");
This is the first time I am attempting to partition something this string dependant. Any suggestions?

 Accepted Answer

Chunru
Chunru on 10 Oct 2022
Edited: Chunru on 15 Oct 2022
websave("scan.txt", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1150740/archer_fieldnotes_scan.txt")
ans = '/users/mss.system.KDDHFr/scan.txt'
%type scan.txt
s = readlines("scan.txt")
s = "northeast section ar20.63 - pos northeast sec ar20.69 - neg NE sec 20.71 - neg NE sect as 20.72 - ? southeast sec am20.70-neg SE sec am20.71 - pos"
x = regexp(s, '(\D+)(\d+\.\d+) - (pos|neg)* ', 'tokens')
x = 1×3 cell array
{["northeast section ar" "20.63" "pos"]} {["northeast sec ar" "20.69" "neg"]} {["NE sec " "20.71" "neg"]}

3 Comments

Thank you, it is close.
I have never used the regexp command and will have to read on how it works.
It looks like you tried using the - as a delininator. Which is a good idea becasuse it is usally common in the text file.
But when doing that the "result" for each line is now strating the next 1x2 string in the cell.
The desired result would be R = 3 x n matrix of the the "position", "value" and the "positions result".
"northeast section ar" "20.63" "pos"
"northeast sec ar" "20.69" "neg"
See above. You can read through regext, which is very powerful.
Ok, cool you used the pos of neg, which is more or less common this will work and I can change the off events where it doesnt mannually. Great, thank you much.

Sign in to comment.

More Answers (0)

Products

Release

R2022a

Asked:

Jon
on 9 Oct 2022

Commented:

Jon
on 17 Oct 2022

Community Treasure Hunt

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

Start Hunting!