How can I delete rows in which a specific value is present?

5 views (last 30 days)
I have a dataset of 12 columns and 70,000 rows. I want to delete the rows in which any of the columns has a value 999.25 as it represents null in my data set. What would be the simplest way of doing this as a beginner?

Accepted Answer

Yongjian Feng
Yongjian Feng on 28 Oct 2021
How about this?
dataset = ones(100, 12); % use your own data instead here
sz = size(dataset);
rowCount = sz(1);
for i=1:rowCount
if any(dataset(i, :) == 999.25)
dataset(i, :) = []; % delete row
end
end

More Answers (1)

Star Strider
Star Strider on 28 Oct 2021
Try something like this —
D = randi(9, 10, 12);
D(randi(numel(D),1,3)) = 999.25
D = 10×12
6.0000 5.0000 5.0000 7.0000 8.0000 1.0000 1.0000 8.0000 4.0000 5.0000 8.0000 5.0000 9.0000 9.0000 7.0000 2.0000 1.0000 5.0000 9.0000 2.0000 9.0000 1.0000 1.0000 2.0000 1.0000 6.0000 6.0000 3.0000 4.0000 5.0000 8.0000 8.0000 2.0000 8.0000 4.0000 999.2500 2.0000 4.0000 3.0000 5.0000 3.0000 3.0000 7.0000 2.0000 9.0000 4.0000 6.0000 999.2500 3.0000 8.0000 2.0000 5.0000 4.0000 4.0000 2.0000 6.0000 3.0000 8.0000 4.0000 4.0000 9.0000 5.0000 7.0000 9.0000 5.0000 5.0000 5.0000 9.0000 9.0000 6.0000 4.0000 8.0000 5.0000 5.0000 3.0000 5.0000 5.0000 3.0000 6.0000 5.0000 4.0000 3.0000 6.0000 6.0000 3.0000 1.0000 999.2500 2.0000 7.0000 2.0000 1.0000 8.0000 5.0000 6.0000 5.0000 7.0000 1.0000 7.0000 6.0000 4.0000 8.0000 3.0000 9.0000 3.0000 2.0000 5.0000 2.0000 5.0000 2.0000 7.0000 6.0000 4.0000 3.0000 3.0000 1.0000 2.0000 3.0000 7.0000 8.0000 3.0000
D = D(~any(D==999.25,2),:)
D = 7×12
6 5 5 7 8 1 1 8 4 5 8 5 9 9 7 2 1 5 9 2 9 1 1 2 3 8 2 5 4 4 2 6 3 8 4 4 9 5 7 9 5 5 5 9 9 6 4 8 5 5 3 5 5 3 6 5 4 3 6 6 1 7 6 4 8 3 9 3 2 5 2 5 2 7 6 4 3 3 1 2 3 7 8 3
This searches for any ‘999.25’ value by row, and then keeps only the rows without that particular value.
.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!