Throwing out bad data

9 次查看(过去 30 天)
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

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by