CSV files sweep [Script]
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi everyone.
I have a script thats loads one CSV per time.
i=0;
cont=0;
s = csvread('scope_1_1.csv', 2, 0);
[fil,col]=size(s);
for i=1:fil
if ((s(i,2))< 0.5)&&(s(i+1,2)-(s(i,2))>2)
cont=cont+1;
if (cont==25)
display(s(i, 1));
break
end
end
end
I have a lot of CSV files, with this estructure scope_1_1.csv , scope_2_1.csv ..... Its posible to optimize this code to execute this script for all the CSV with only one iteration?
댓글 수: 0
답변 (1개)
Guillaume
2015년 3월 24일
Your code will fail if i happens to reach fil, since s(i+1, 2) is then not valid.
You will need a loop to go over the different csv files, but you certainly don't need a loop for finding your row:
s = csvread('scope_1_1.csv', 2, 0);
thresholdindices = find(s(1:end-1, 2) < 0.5 & diff(s(:, 2)) > 2, 25);
if numel(thresholdindices) < 25
error('there was less than 25 values that matched the threshold');
end
thresholdvalue = s(thresholdindices(end), 1);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!