Capturing partial coordinates from text file...
Show older comments
I want to read a gcode-file into matlab.. The format looks something like below...
;LAYER:0
M107
G0 F9000 X89.19 Y90.68 Z0.30
;TYPE:SKIRT
G1 F1200 X89.40 Y91.83 E0.05822
G1 X89.67 Y92.97 E0.11703
G1 X90.01 Y94.10 E0.17553
I want to read the G0 and G1 commands, describing positions.. The input not complete and may not hold all coordinates in all lines.. The output I'm looking for is a array (or a table) with the X, Y and Z movements, with a NaN or zero when values are missing.. So something like this:
89.19 90.68 0.30
89.40 91.83 NaN
89.67 92.97 NaN
90.01 94.10 NaN
I've been trying to use regexp, but can't really wrap my head around it..
I've already made a loop based reader, that splits the strings and examines if with IF-statements, but this is timeconsuming, as these files may hold hundred of thousands of commands....
Accepted Answer
More Answers (0)
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!