MATLAB: Throwing out bad data

datadelete rowsfilter dataisnan

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

Best Answer

You don't need to loop:
x = x(count == 10,:);