필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Read spesific rowintervals from .txt file and store them

조회 수: 2 (최근 30일)
Henning Eimstad
Henning Eimstad 2020년 3월 25일
마감: MATLAB Answer Bot 2021년 8월 20일
I am trying to read a large .txt doc that continues for maany rows. I have tried to do it manually by the following code:
for i = 12
C = textscan(fid,'%.6f %.6f',npoints,'delimiter','\n', 'headerlines',i-1);
p1 = C{1}*1e3;
y1 = C{2};
py1 = [p1 y1];
end
for i = 40
C = textscan(fid,'%.6f %.6f',npoints,'delimiter','\n', 'headerlines',i-1);
p2 = C{1}*1e3;
y2 = C{2};
py2 = [p2 y2];
end
for i = 68
C = textscan(fid,'%.6f %.6f',npoints,'delimiter','\n', 'headerlines',i-1);
p3 = C{1}*1e3;
y3 = C{2};
py3 = [p3 y3];
end
Is it possible to do this is one loop ? the number of rows are equal for all the "intervals" such that "npoints" is fixed 21. and it is 28 spaces between each interval so I was thinking something like for i = [12:28:1356] where 1356-1376 is the last interval.

답변 (1개)

KSSV
KSSV 2020년 3월 25일
I = [12 40 68] ;
iwant = cell(length(I),1) ;
for i = 1:length(I)
C = textscan(fid,'%.6f %.6f',npoints,'delimiter','\n', 'headerlines',I(i)-1);
p1 = C{1}*1e3;
y1 = C{2};
py1 = [p1 y1];
iwant{i} = py1 ;
end
  댓글 수: 4
Henning Eimstad
Henning Eimstad 2020년 3월 25일
Well, it works when I check for just I = 12, I = 40 etc, but it doesnt work with I = [12 40 68 ..... ]. Cant see why that should be a problem?
Henning Eimstad
Henning Eimstad 2020년 3월 25일
For some reason, the first value read for line 40 when I use I = [12 40] is from line 72 and not 40...

이 질문은 마감되었습니다.

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by