How to figure out which rows I delete and record them?

3 views (last 30 days)
So I have the following code
function [Vnew, rows_removed] = removerows(V)
x = isfinite(V);
y = all(x,2);
Vnew=V(y,:)
rows_removed = V==Vnew
end
what this does is it takes the rows that have an NaN in them and deletes it. So for example, if my matrix
V =[ 1 9 0 8; 7 2 NaN 13; 4 2 10 0; 1 Inf 14 7 ]
then Vnew will be
Vnew = [ 1 9 0 8; 4 2 10 0; ];
I cannot however get the second part to work which would tell me which rows I deleted. SO for this example, it would be
rows_removed = [2, 4];
Any ideas? Thanks!

Answers (1)

KSSV
KSSV on 6 Dec 2016
You may follow something like below:
V =[ 1 9 0 8; 7 2 NaN 13; 4 2 10 0; 1 Inf 14 7 ] ;
Vnew = [ 1 9 0 8; 4 2 10 0; ];
% get row of NaN
[r1,c1] = find(isnan(V)) ;
%get inf
[r2,c2] = find(isinf(V)) ;
% remove those rows
V([r1 r2],:) = []

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!