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

조회 수: 3 (최근 30일)
PenguinForce
PenguinForce 2016년 12월 6일
답변: KSSV 2016년 12월 6일
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!

답변 (1개)

KSSV
KSSV 2016년 12월 6일
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],:) = []

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by