필터 지우기
필터 지우기

CSV files sweep [Script]

조회 수: 2 (최근 30일)
Antonio Jayena
Antonio Jayena 2015년 3월 24일
답변: Guillaume 2015년 3월 24일
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?

답변 (1개)

Guillaume
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);

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by