Extract and plot from .txt file
Ältere Kommentare anzeigen
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!
Antworten (1)
madhan ravi
am 29 Mär. 2019
Bearbeitet: madhan ravi
am 31 Mär. 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,:))
Kategorien
Mehr zu Text Data Preparation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!