Throwing out bad data

11 views (last 30 days)
Kendra Wright
Kendra Wright on 10 Nov 2014
Commented: Kendra Wright on 10 Nov 2014
I have a large data set where sometimes we have a "bad" data point. The the column "count" in the matrix "x" below, I have the value 10 if all of the data points were taken, or NaN or some other number if there was a problem. I'm working on filtering out those points. So when I have count(i) does not equal 10, I want to delete the entire row.
This is most certainly not the simplest way of doing this, but I am trying to run two separate loops to search for bad data points and delete the row. The first loop which looks for numbers not equal to 10 seems to work. The second loop does not, although it deletes most of the values of the points that have a NaN value (all but 3). Could someone either help me see how to fix this piece of code or suggest a different method?
L = length(Data{1});
x = horzcat(DateNumber,RedScat,GreenScat,count);
for i=1:L
if count(i) ~= 10
x(i,:)=[];
end
end
L2 = length(x);
countedit = x(:,end);
y = isnan(countedit);
for i=1:L2
if y(i) == 1
x(i,:)=[];
end
end

Accepted Answer

Kelly Kearney
Kelly Kearney on 10 Nov 2014
You don't need to loop:
x = x(count == 10,:);
  1 Comment
Kendra Wright
Kendra Wright on 10 Nov 2014
Wow, I knew I was making that much more difficult than necessary. Thank you

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!