MATLAB: How to read information from a .txt file and convert it into a matrix

text filetextscanvectorization

Hello, I need to read information from a text file and convert that information into a matrix or a set of vector columns which i can later use.
The information contained in that text file is always in this format ("name_of_something – 45.00 30.45" – basically a name followed by a dash and by two numbers with two decimal algorithms with a space between all of them). The text file i am using goes bellow.
Annotation 2019-12-16 014349.jpg
I need to convert that information into a matrix with three columns, one with the name, one with the first numerical value and the last one with the other numerical value.
I dont know how i can do this. I have managed to get it into a cell array by line but that's not quite what i wanted…
Annotation 2019-12-16 014443.jpg
Was really hoping you could help me.
Thanks a lot in advance!

Best Answer

S = fileread('frotatego');
info_struct = regexp(S, '^(?<name>.*?)\s+(?<val1>\d+\.\d\d)\s+(?<val2>\d+\.\d\d)\s*$', 'names', 'dotexceptnewline', 'lineanchors');
names = {info_struct.name};
val1 = str2double({info_struct.val1});
val2 = str2double({info_struct.val2});
T = table(names, val1, val2);
(Not tested as my system is busy at the moment)