フィルターのクリア

reverse indexing with conditions

9 ビュー (過去 30 日間)
cgo
cgo 2015 年 11 月 9 日
コメント済み: cgo 2015 年 11 月 9 日
Let A = [1 2 4 6 10], I want to find the indices of the matrix for which the element less than 5.
So if I say: A < 5, then it will return [1 1 1 0 0]. How can I proceed to get the index of all those 1's?
Thanks

採用された回答

TastyPastry
TastyPastry 2015 年 11 月 9 日
idx = 1:numel(A);
mask = A < 5;
idx = idx(mask);
  1 件のコメント
cgo
cgo 2015 年 11 月 9 日
thanks

サインインしてコメントする。

その他の回答 (1 件)

Thorsten
Thorsten 2015 年 11 月 9 日
編集済み: Thorsten 2015 年 11 月 9 日
To get numerical indices, use find
idx = find(A < 5);
You can also use logical indices, that are often faster:
idx = A < 5;
In both cases you get the indexed numbers using
A(idx)
  1 件のコメント
cgo
cgo 2015 年 11 月 9 日
perfect. thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by