How can I repeat an iteration after if has been verified?
13 views (last 30 days)
Show older comments
My current script can remove 1 outlier per row of data by performing a grubbs test and removing the maximum if it fails.
I would like the script to be able to rerun a row after it has removed an outlier, to determine if there are more outliers (and remove them if necessary). The Grubbs test used here returns a value 'h' of 0 or 1 for either not finding, or having found an outlier. All outliers are positive in this case.
The script currently replaces all '8's in matrix r, but not the secondary outlier '7.9'.
r = [8 5 5 5 5 5 7.9 5 5 5;5 8 5 5 5 5 5 5 5 5;5 5 8 5 5 5 5 5 5 5;5 5 5 8 5 5 5 5 5 5;5 5 5 5 8 5 5 5 5 5;5 5 5 5 5 8 5 5 5 5;5 5 5 5 5 5 8 5 5 5;5 5 5 5 5 5 5 8 5 5;5 5 5 5 5 5 5 5 8 5;5 5 5 5 5 5 5 5 5 8;];
h = zeros(10,1);
for g = 1:10
h(g,:) = Grubbs(r(g,:),0.05,'right');
if h(g,:) == 1
[value, location] = max(r(g,:));
r(g,location) = NaN;
end
Thanks!
0 Comments
Accepted Answer
Azzi Abdelmalek
on 24 Aug 2013
Use a while loop instead a for loop
g=1;
while g <10
h(g,:) = Grubbs(r(g,:),0.05,'right');
if h(g,:) == 1
[value, location] = max(r(g,:));
r(g,location) = NaN;
else
g=g+1;
end
end
2 Comments
Azzi Abdelmalek
on 24 Aug 2013
Try this
g=1;
while g <10
h(g,:) = Grubbs(r(g,:),0.05,'right');
if h(g,:) == 1
[value, location] = max(r(g,:));
r(g,location) = NaN;
if all(isnan(r(g,:)))
g=g+1;
end
else
g=g+1;
end
end
More Answers (0)
See Also
Categories
Find more on Hypothesis Tests 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!