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 Center および File ExchangeStatistics 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