How to read only numbers from the file of following format
(title "dm_m")
(labels "dm_m" "Position")
((xy/key/label "point_40")
0.000128835 18.1347
)
((xy/key/label "point_41")
-4.16311e-06 20.2711
)
((xy/key/label "point_42")
8.93259e-05 22.4074
)
((xy/key/label "point_43")
0.000130064 24.5438
)
((xy/key/label "point_44")
0.000131733 26.6802
)
((xy/key/label "point_45")
0.000147312 28.8166
)
((xy/key/label "point_46")
0.000141488 30.9529
)
((xy/key/label "point_47")
0.000136125 33.0893
)
)

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 17일
편집: Azzi Abdelmalek 2015년 7월 17일

0 개 추천

Edit
fid=fopen('file.txt')
a=textscan(fid,'%s')
fclose(fid)
c=regexp(a{:},'\<(+|-|\.|\d)\d*(\.)?(\d+)?','match')
f=c(~cellfun(@isempty,c))
out=reshape(str2double([f{:}]'),2,[])

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2015년 7월 17일
편집: Andrei Bobrov 2015년 7월 17일

1 개 추천

f = fopen('data_in_your_format.txt');
c = textscan(f,'%s','delimiter','\n');
fclose(f);
c = c{:};
[~,~,~,z] = regexp(c,'-*\d+\.\d+(e-*\d+)*');
z1 = z(~cellfun(@isempty,z));
out = str2double(reshape([z1{:}],2,[])');

댓글 수: 2

DJ
DJ 2015년 7월 17일
편집: Stephen23 2015년 7월 17일
Thank you code 2 works perfectly if the numbers are positive but if numbers are negative it doesn't work. Is there some modification to be done? If the numbers are mix of positives and negatives
Andrei Bobrov
Andrei Bobrov 2015년 7월 17일
편집: Andrei Bobrov 2015년 7월 17일
corrected 2

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

카테고리

질문:

DJ
2015년 7월 17일

편집:

2015년 7월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by