Extract and plot from .txt file
Show older comments
Hi! I want to build a script that is able to extract points from a .txt file and do a 3D plot. The text file looks like this:
Element Real Nominal Desviac. Tol. sup. Tol. inf. Dent./Fue.
(Desv TP) (Tol TP)
Point: Point-2[1,1](ID:1, from 1 point)
Coord. X = 183,250100
Coord. Y = 253,308300
Coord. Z = 25,185977
Point: Point -2[1,2](ID:2, from 1 point)
Coord. X = 183,250200
Coord. Y = 251,308200
Coord. Z = 25,177848
NOT VALID ELEMENT: POINT-2[1,4](ID:3, from 1 point)
****
****
****
Point: Point -2[1,3](ID:4, from 1 point)
Coord. X = 183,250200
Coord. Y = 249,308200
Coord. Z = 25,171169
...
I tried different ways but my code is not working. How can I do it?
Thank you in advance!
Answers (1)
madhan ravi
on 29 Mar 2019
Edited: madhan ravi
on 31 Mar 2019
fid = fopen('sample.txt'); % name of your text file
f = textscan(fid,'%s','delimiter','\n');
fclose(fid);
z = f{:};
Z=regexprep(z(contains(z,'=')),',','.'); % interpreting comma as dot
func = @(x) regexp(x,'\d+[\.?]\d*','match','once');
Datas = reshape(str2double(cellfun(func,Z,'un',0)),3,[]); % 3 represents x,y,z so three rows
plot3(Datas(1,:),Datas(2,:),Datas(3,:))
Categories
Find more on Text Data Preparation 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!