MATLAB: How to extract numeric data from a textfile

coordinatedataplotscantext filexy

Hi all, is there a method in which I would be able to extract x and y coordinate data from a textfile, when the x and y values are divided by a '/'?
I need to extract and then plot the coordinate data.
The textfile should be attached above. Any help would be greatly appreciated. Thanks 🙂

Best Answer

S = fileread('P01-GroupM(1).txt');
XYstrs = regexp(S, '^X/Ycoords \(in):\s*(?<X>\S+)\s*/\s*(?<Y>\S+)', 'names', 'lineanchors', 'dotexceptnewline');
X = str2double({XYstrs.X});
Y = str2double({XYstrs.Y});
plot(X, Y)
axis equal
Related Question