CSV files sweep [Script]
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Guillaume
on 24 Mar 2015
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 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!