CSV files sweep [Script]

3 次查看(过去 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 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by