フィルターのクリア

Indices to zeros in Matrix

139 ビュー (過去 30 日間)
RDG
RDG 2013 年 9 月 10 日
Suppose:
A =
4 5 1 3
5 1 3 4
5 0 0 0
6 0 0 0
4 0 0 0
4 0 0 0
3 0 0 0
I want to find the indices to the rows that contain 0 and I used:
[r,c]=find(A==0)
However, r returned
3
4
5
6
7
3
4
5
6
7
3
4
5
6
7
Why is this so? Shouldn't it return 3,4,5,6,7 only?

採用された回答

Evan
Evan 2013 年 9 月 10 日
[r,c] = find(A == 0) returns in r and c the row and column indices of every single zero in the array. Therefore, you're going to get multiples like that. If you want to find which rows contain zeros rather than where each zero is located, you could do one of the following:
r = find(any(~A,2));
Or:
[r,c] = find(A == 0);
r = unique(r);
The first option is preferable, as it is much faster.

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 10 日
find(any(~A,2))

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by