フィルターのクリア

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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by