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
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 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!