read certain range in csv file and save to new file

조회 수: 2 (최근 30일)
louis za
louis za 2019년 3월 15일
댓글: Star Strider 2019년 3월 18일
Hi guys,
I have a one column data contain 100 000 rows.
i need to extract a data for range 0-0 and save it into new file.
example of my data:
0
1
2
3
4
5
0
6
7
4
3
5
6
0
6
43
5
7
5
0
7
4
60
0
Then, for a new file it should contains 0 1 2 3 4 5 0 in column , the second file is 0 6 7 4 3 5 6 0 and so on.
  댓글 수: 2
dpb
dpb 2019년 3월 15일
Is the file guaranteed to begin/end with 0 entry?
louis za
louis za 2019년 3월 16일
yes because it is speed profile

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

채택된 답변

Star Strider
Star Strider 2019년 3월 16일
A loop is the only (and likely the simplest) option, since you need the zero values on both ends of each sub-vector:
V = [0
1
2
3
4
5
0
6
7
4
3
5
6
0
6
43
5
7
5
0
7
4
60
0];
idx = find(V == 0);
for k1 = 1:numel(idx)-1
Out{k1} = V(idx(k1):idx(k1+1));
end
  댓글 수: 4
louis za
louis za 2019년 3월 18일
thankyou for your help
Star Strider
Star Strider 2019년 3월 18일
As always, my pleasure.

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

추가 답변 (1개)

dpb
dpb 2019년 3월 16일
Same basic solution but one can write the loop without an explicit loop -- of course, it could easily be found to be less efficient than the deadahead solution besides the complexity, but just as exercise:
idx=find(V == 0);
idx=reshape([idx(1);kron(idx(2:end-1),ones(2,1));idx(end)],2,[]);
out=arrayfun(@(i1,i2) V(i1:i2),idx(1,:),idx(2,:),'uni',0);

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by