# extraction of numeric data with presence of text data

조회 수: 23(최근 30일)
Abhijit Sardar 2 Apr 2021
댓글: dpb 5 Apr 2021
I want to extract x,y co-ordinate and amplitude data from the txt file but i am not getting any idea how to do so.
for eg.:- * Gp# 1[8,4] x,y = -14.46, 0 dT[7] Src Amplitude = 36.0
then i want output as
x y amplitude
1. -14.46 0 36.0
2.
3. and so on

댓글을 달려면 로그인하십시오.

### 채택된 답변

dpb 2 Apr 2021
편집: dpb 3 Apr 2021
fid=fopen('abc.txt','r');
fid=fclose(fid);
abc=string(abc{:});
abc=abc(contains(abc,'Gp#'));
xy=str2double(split(extractBetween(abc,'x,y = ',' dT'),','));
ampl=str2double(extractAfter(abc,'Amplitude = '));
tABC=table(xy(:,1),xy(:,2),ampl,'VariableNames',{'x','y','amplitude'});
results in
ans =
8×3 table
x y amplitude
______ ____ _________
-14.46 0.00 36.00
-14.46 0.00 35.00
13.39 0.00 34.00
-18.75 0.00 32.00
19.82 0.00 36.00
-20.89 0.00 32.00
19.82 0.00 50.00
-5.89 0.00 36.00
>>
##### 댓글 수: 6표시숨기기 이전 댓글 수: 5
dpb 5 Apr 2021
Well, give it a go and post your code and specific Q? if you get stuck...

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by