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

3 vues (au cours des 30 derniers jours)
PenguinForce
PenguinForce le 6 Déc 2016
Réponse apportée : KSSV le 6 Déc 2016
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!

Réponses (1)

KSSV
KSSV le 6 Déc 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],:) = []

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by