Extract and plot from .txt file

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!

回答(1 个)

madhan ravi
madhan ravi 2019-3-29
编辑:madhan ravi 2019-3-31
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,:))

类别

帮助中心File Exchange 中查找有关 Text Data Preparation 的更多信息

产品

版本

R2018b

提问:

2019-3-29

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by