read certain range in csv file and save to new file
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
추가 답변 (1개)
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!